title: ASP.NET MVC Razor - if inside for
body: <p>I'm trying to output an HTML table using razor. The table itself works, but now I'm trying to add a class called "even" to every other row in the table:</p>
  
  <pre><code>&lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Column 1&lt;/th&gt;
              &lt;th&gt;Column 2&lt;/th&gt;
              &lt;th&gt;Column 3&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @for (int i = 0; i &lt; ViewBag.MyList.Count; i++)
          {
              var myObject = ViewBag.MyList[i];
              &lt;tr @if (i % 2 == 0 ) { class="even" }&gt;
                  &lt;td&gt;myObject.Column1&lt;/td&gt;
                  &lt;td&gt;myObject.Column2&lt;/td&gt;
                  &lt;td&gt;myObject.Column3&lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>There's obviously something wrong with that if-case inside the loop, but what is the correct way of writing this?</p>