How to deal with apparently mismatched HTML tags in Razor Engine?
Here is the case:
@{
if (A)
{
<div>
<span>bla</span>
<!-- This is where it breaks! -->
}
else
{
<span>bla</span>
}
if(B)
{
</div>
}
}
Since the <div>
isn't closed inside the same condition where it's opened, Razor Engine thinks that the else statement is HTML mark-up. What could I possibly do in situations like this to m开发者_如何学JAVAake it work properly?
The problem is mismatched html tags. The easy way around this is to use the @:
parser directive
@{
bool A = true;
bool B = true;
if (A)
{
@:<div>
<span>bla</span>
<!-- This is where it breaks! -->
}
else
{
<span>bla</span>
}
if(B) {
@:</div>
}
}
精彩评论