asp.net mvc - Is checking ViewBag.Val != null correct in Razor? -


what's proper way check in razor if viewbag has value set? know i can do

if(viewbag.foo != null) {   ... } 

but looking in events stream in vs 2015 notice generates (handled) runtimebinderexception.

the fact throws error leads me suspect not correct way check presence of value, , harming performance (though have not done testing). in addition doesn't distinguish between value being absent , value being set null.

is there more correct approach?

there no way defined razor developers, can see this using extension method.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -