In MVC4, is it possible for ViewBag
to ever be null
? If so, under what scenarios could it be? If not, how do you know?
Specifically, I want to know if it can be null
in a view. However, additional information about whether it can be null
in a controller would be useful.
For example, do I need to perform a null
check?
if (ViewBag != null && ViewBag.Something != null && ViewBag.Something.Foo == "Bar")
{
// can ViewBag be null?
}