What's the proper way to check in Razor if ViewBag has a value set? I know that I can do
if(ViewBag.Foo != null) {
...
}
But looking in the events stream in VS 2015 I notice this generates a (handled) RuntimeBinderException
.
The fact that this throws an error leads me to suspect that this is not the correct way to check the presence of a value, and is actually harming performance (though I have not done any testing). In addition it doesn't help you distinguish between a value being absent and the value being set to null
.
Is there a more correct approach?