asp.net - Adding logic to view causes parse error? -


i have view looks following:

@foreach(var project in @model.projects.orderby(t=>t.projecttypeid)) {    <h4>@project.projecttype.name</h4>    <table class="table table-hover">    ...   </table> } 

which works fine. wanted add logic around portion creates table:

@foreach(var project in @model.projects.orderby(t=>t.projecttypeid)) {    bool rendertable = true;    if(rendertable)    {           <h4>@project.projecttype.name</h4>       <table class="table table-hover">    }    ...     @if(rendertable)     {         </table>     } } 

but causing parse error:

parser error  description: error occurred during parsing of resource required service request. please review following specific parse error details , modify source file appropriately.   parser error message: foreach block missing closing "}" character.  make sure have matching "}" character "{" characters within block, , none of "}" characters being interpreted markup.   source error:    line 15:  line 16:  line 17: @foreach(var project in @model.projects.orderby(t=>t.projecttypeid)) line 18: { 

can see cause this? when search matching brackets in visual studio seems legit.

since don't close <table> element, razor considering ending } part of html hence @if { block not closed.

try this:

@:<table class="table table-hover"> 

or:

if (rendertable) {        <text>        <h4>@project.projecttype.name</h4>        <table class="table table-hover">    </text> } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -