Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor Syntax Not working the way I expected

having some trouble with my razor syntax

gives a Parsor error saying that The foreach block is missing a closing "}" character

<ul>
@{var client = "null";}
@foreach (var instance in Model)
{
   if (instance.tbl_Policy.tbl_Client.txt_clientName != client)
   {
       client = instance.tbl_Policy.tbl_Client.txt_clientName;
      </ul><h1>@client</h1>   
      <ul>
   }
   <li>
    @instance.tbl_Policy.txt_policyNumber - 
    Assigned to : @instance.aspnet_Membership.aspnet_User.UserName
    @instance.ATLCheckType.Question
   <button type="button" rel="<%:instance.ATLCheckInstanceId.ToString()%>">DelFiled</button>
   <button type="button" rel="<%:instance.ATLCheckInstanceId.ToString()%>">DelLineItem</button>
   </li>  
}
</ul>
like image 616
MarkKGreenway Avatar asked Dec 04 '22 23:12

MarkKGreenway


1 Answers

Razor cannot handle imbalanced HTML tags in code blocks.

Change your if block to treat the imbalanced tags as plain text:

   if (instance.tbl_Policy.tbl_Client.txt_clientName != client)
   {
       client = instance.tbl_Policy.tbl_Client.txt_clientName;
      @:</ul><h1>@client</h1>   
      @:<ul>
   }
like image 169
SLaks Avatar answered Dec 30 '22 09:12

SLaks