asp.net mvc - razor syntax confusion if / then -


i have code block works fine

@foreach (var message in model.orderby(a => a.messageorder)) {     if ((datetime.compare(message.messagestart, datetime.now) < 0) &&        (datetime.compare(message.messageend, datetime.now) > 0))     {      if (!message.hideheader)     {         @html.raw(string.format("<{0}>{1}</{0}>", message.headerclass,          (string.isnullorempty(message.headerhtml)) ? message.header :           server.htmldecode(message.headerhtml)));     }     switch (message.numcolumns)     {         case 1:             @html.partial("_contentblock", message)             break;         default:             <div class="row">                 @html.partial("_contentblock", message)             </div>             break;     } } } 

but tried putting div around code based on if/then , can't razor syntax correct. in visual studio intellisence not highlight if (!message.hideheader) on. not getting errors -

@foreach (var message in model.orderby(a => a.messageorder)) {     if ((datetime.compare(message.messagestart, datetime.now) < 0) &&      (datetime.compare(message.messageend, datetime.now) > 0)) {     if (!string.isnullorempty(message.msgclass))     {         <div class="@message.msgclass">     }     if (!message.hideheader)     {         @html.raw(string.format("<{0}>{1}</{0}>", message.headerclass, (string.isnullorempty(message.headerhtml)) ? message.header : server.htmldecode(message.headerhtml)));     }     switch (message.numcolumns)     {         case 1:             @html.partial("_contentblock", message)             break;         default:             <div class="row">                 @html.partial("_contentblock", message)             </div>             break;     }     if (!string.isnullorempty(message.msgclass))     {         </div>     } } } 

any ideas appreciated

prefix html markup within code block @:

if (!string.isnullorempty(message.msgclass)) {     @:<div class="@message.msgclass"> }  <!-- other code goes here -->  @if (!string.isnullorempty(message.msgclass)) {     </div> } 

the @: tells compiler start of html block inside c# code block.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -