What is PHP's isset equivalent in c# .NET 4 for properties of 'dynamic' objects? -


i working mvc 3 @ moment use viewbag. test if 1 of properties of viewbag has been assigned. know in php isset(variable), there similar in .net 4?

the scenario making nested layout takes section title , section subtitle through viewbag. seperated seperator , sub title optional. don't want display seperator if sub title not set.

this how imagine isset replaced .net 4 equivelant.

@section header  {     <h2>@viewbag.sectiontitle</h2>     @if(isset(viewbag.sectionsubtitle))      {          <div id="section-title-seperator"> - </div><h3>@viewbag.sectionsubtitle</h3>      } } 

next direct answer question, i'm open alternate solutions (in case i'm abusing viewbag).

thanks in advance.

you can check if null this:

@if(viewbag.sectionsubtitle != null).

isset() in php checks if there value present. manual:

isset() return false if testing variable has been set null

you can use viewdatadictionary.containskey on viewdata property. because viewdata["sectionsubtitle"] equavilient viewbag.sectionsubtitle in case do:

@if(viewdata.containskey("sectionsubtitle"))


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -