royco
royco

Reputation: 5529

How to debug ASP.NET MVC Controller after it passes control to the View?

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?

Upvotes: 3

Views: 1476

Answers (4)

Craig Stuntz
Craig Stuntz

Reputation: 126587

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

Upvotes: 2

BigBrother
BigBrother

Reputation: 1100

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.

Upvotes: 1

Mathias F
Mathias F

Reputation: 15931

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

Upvotes: 3

TJB
TJB

Reputation: 13497

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

Upvotes: 1

Related Questions