2

I've got the following simple code:

@for (int j = 0; j < file.Items.Count; j++) {
var item = file.Items[j];
if (item.Errors.Count > 0)
{
    Html.Raw("<tr class='errors'>");
}
else {
    Html.Raw("<tr>");
}
    <td>blah</td>
    </tr>
}

However, I keep getting a parsing error saying that the closing </tr> has no opening tag. What am I missing? If I replace the if statement with a regular <tr> then it works fine.

nemesv
  • 138,284
  • 16
  • 416
  • 359
devlife
  • 15,275
  • 27
  • 77
  • 131

2 Answers2

1

I believe it is just an intellisense problem, try this hack:

@for (int j = 0; j < file.Items.Count; j++) {
   var item = file.Items[j];
   if (item.Errors.Count > 0)
   {
       @:<tr class="errors">
   }
   else {
       @:"<tr>");
   }
       @:<td>blah</td>
       @:</tr>
 }

I think your code is perfectly OK, check this SO question for great explanations of this.

Hope it helps!

Community
  • 1
  • 1
Cacho Santa
  • 6,846
  • 6
  • 41
  • 73
0

try losing the Html.Raw in both cases. I don't see why you need them

raklos
  • 28,027
  • 60
  • 183
  • 301