Search code examples
c#asp.net-mvcvisual-studiorazor

How to view ViewBag content while debugging in Visual Studio?


How can I easily view the contents of a ViewBag while debugging ASP.NET MVC controllers in Visual Studio?

As a workaround, I use temporary variables:

string tmp = ViewBag.MyData;

So, the problem is that viewing ViewBag.MyData directly is difficult, tmp is easy.


Solution

  • To view the contents of ViewBag when debugging:

    • At a breakpoint...
    • Open (Debug menu / QuickWatch) and type in ViewBag.
    • Click the arrows at the left-hand-side for ViewBag, then for Dynamic.
    • The contents of ViewBag will be displayed.

    enter image description here