views:

199

answers:

4

About once every 20 page loads, I get a glitch in my View. I'd like to know what values the variables in my Controller contained right before it called the View. However, once the View is called I lose all local variables from the Controller. Is there any hope?

+1  A: 

You could add extra output on your view page to show you variable value / states for debugging information until you resolve the issue.

TJB
+3  A: 

Use ModelVisualizer Helper in mvc.contrib It renders all values into the view.

Malcolm Frexner
This looks very useful. I can't quite get it to work though. I've incorportated it as an HTML Helper, but when rendering the ModelVisualizer I just see "There is no data in ViewData". However, I know my Model isn't empty. Any thoughts?
Slack
Hmm, maybe it's not working for me because I'm on MVC 2 preview 2.
Slack
Oh I didnt check yet with MVC 2...:-(I will post a bugfix if it is realy not working in MVC 2
Malcolm Frexner
Does it only work with public properties in the Model?
Slack
Yes. Private properties are not accessible in the view.
Malcolm Frexner
+1  A: 

Apologies if I'm missing something obvious but can't you set a conditional breakpoint in the Controller just prior, or on, the View call? The condition can be based on execution count. Once stopped you can step into the View.

I realize you lost the Controller local variables as they are out of scope as soon as you step into the View but can't be that hard to write them down, append to a large string (ie Flash message) and output in view, etc.

Joe
Yes, but I have many variables and currently have no idea where the problem lies. I was hoping for a more straightforward way to do this, something like the ability to set a retroactive breakpoint.
Slack
+2  A: 

The watch window's "Make Object ID" feature will let you watch variables which are out of scope.

Craig Stuntz
This looks promising, but I don't quite have the hang of it. I see the menu Bruno is talking about, but I don't have the Make Object ID option listed. I'll have to read up on it more.
Slack