C# get properties of the ViewBag?

c#, viewbag

Solution

Check ViewData - it contains everything in ViewBag in a form of a Dictionary.

Problem

I get the whole idea of the fact that `ViewBag` is dynamic, and that new properties can be "added" to the `ViewBag` by using and initializing those properties for the first time without compilation issues. However, I'm looking for a way to get all the properties that have been initialized on the `ViewBag`. `ViewBag` (according to MSDN) is declared as an object in the `ControllerBase` class, and there appears to be no method on how to get the properties of the object dynamically. Perhaps reflection, but then again, I wouldn't know where to start. The reason I want to do this is that I am converting a huge website from MVC to MVVM architecture. For that purpose I want to make tests that make sure that the ViewBag is not used anywhere, and that no properties on the ViewBag have been set after a controller's method has been run. Where do I start?

Original source