Porting from https://aspnet.codeplex.com/workitem/8641:
The razor parser checks HTML tags to assure they are balanced. This seems like a nice thing to do except it does this check only within the current code block (between the same set of braces, for example). We ran into this when looping through a list of strings and doing layout by making the even-index strings on the left and odd-index strings on the right, two to a row. Each row is enclosed in a div. We tried to insert the outer div open tag before even indexes and the div close tag after the odd indexes, but this fails even though it seems like a reasonable thing to do. Something like below will fail because the "if" statement contains an open div tag, but no close. The div close tag is in a different if statement. Sure, there are work-arounds. (loop and outer code block omitted):
bool even = (0 == (i % 2));
var name = myNames[i];
if (even)
{
<div id="outerDiv">
<div class="leftColumn">@name</div>
}
// some other markup added here
if (!even)
{
<div class="rightColumn">@name</div>
</div>
}
Comments: We want to consider adding an explicit operator to go back from markup to C#.
The razor parser checks HTML tags to assure they are balanced. This seems like a nice thing to do except it does this check only within the current code block (between the same set of braces, for example). We ran into this when looping through a list of strings and doing layout by making the even-index strings on the left and odd-index strings on the right, two to a row. Each row is enclosed in a div. We tried to insert the outer div open tag before even indexes and the div close tag after the odd indexes, but this fails even though it seems like a reasonable thing to do. Something like below will fail because the "if" statement contains an open div tag, but no close. The div close tag is in a different if statement. Sure, there are work-arounds. (loop and outer code block omitted):
bool even = (0 == (i % 2));
var name = myNames[i];
if (even)
{
<div id="outerDiv">
<div class="leftColumn">@name</div>
}
// some other markup added here
if (!even)
{
<div class="rightColumn">@name</div>
</div>
}
Comments: We want to consider adding an explicit operator to go back from markup to C#.