How can I write the following statement with Razor?
@{
if (isOddRow)
{
<tr class="PadColumns">
}
else
{
<tr class="PadColumns AlternateRow">
}
//then...
<td>content</td>
</tr>
}
Razor gets mad and Intellisense busts.
so I tried wrapping my tr's in <text>
if (isOddRow)
{
<text><tr class="PadColumns"></text>
}
…which causes a runtime parser error regarding tr with no matching start tag.
I would like to apply DRY by avoiding
if (isOddRow)
{
<tr class="PadColumns">
//then...
<td>content</td>
</tr>
}
else
{
<tr class="PadColumns AlternateRow">
//then...
<td>content</td>
</tr>
}
Why not just do something like this? Put the if statement inside the class attribute. If it’s false, it’ll print out AlternateRow, otherwise it prints out nothing.