简体   繁体   中英

List content of ViewBag in view

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM