title: asp.net mvc - Simplest way to provide alternate row styling in Razor
body: <p>Given the following Razor code:</p>
  
  <pre><code>&lt;tbody&gt;
      @foreach (Profession profession in Model)
      {
          &lt;tr&gt;
              &lt;td&gt;@profession.Name&lt;/td&gt;
              &lt;td&gt;@profession.PluralName&lt;/td&gt;
              &lt;td&gt;@Html.ActionLink("Edit", "AddOrEdit", new { Id = profession.ProfessionID })&lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/tbody&gt;
  </code></pre>
  
  <p>What's the simplest way to provide some kind of alternate row styling? (i.e. different styling for odd and even rows.)</p>
  
  <p>I don't seem to be able to add arbitrary C# to declare a <code>bool</code> variable which gets flipped each iteration of the <code>foreach</code> loop in order to set a classname for the <code>tr</code>, for example.</p>