Reputation: 10824
For debugging I want to dump the contents of my ViewBag inside a comment in my View. This seems like it would be relatively simple but there are no tutorials that even approach this. Details of the ViewBag seem to be scarce.
So how can I dump the contents of my ViewBag in my View? Assume no complex types like lists, etc. Links to a source that give in depth details about eh VB are a plus.
Upvotes: 3
Views: 4153
Reputation: 3870
You can do it with ViewData
instead. Like this
<ul>
@foreach(var pair in ViewData)
{
<li>@pair.Key : @pair.Value</li>
}
</ul>
To learn why ViewData
may be used instead of ViewBag
please have a look in here. Check the question and the accepted answer by Darin Dimitrov.
Upvotes: 8