title: Foreach loop counter in MVC Razor
body: <p>What I am attempting to accomplish is to set an alternating row on a table to a different CSS style.</p>
  
  <p>My controller returns a simple list and passes that to the view by way of the ViewBag.</p>
  
  <p>My View code is as follows:</p>
  
  <pre><code>@{
      int _recordCount = 1;
      foreach (var _oEstimateDetails in ViewBag.EstimateDetailData)
      {
          if (_recordCount == 1)
          {
              &lt;tr class="EstimateDetailDataRow"&gt;
          }
  
          if (_recordCount == 1)
          {
              &lt;/tr&gt;&lt;tr class="EstimateDetailDataAlternateRow"&gt;
              _recordCount = 0;
          }
          &lt;/tbody&gt;
          &lt;td class="EstimateDetailData"&gt;
              @_oEstimateDetails.EstimateLineDescription
          &lt;/td&gt;
          &lt;td class="EstimateQuantityData"&gt;
              @_oEstimateDetails.EstimateLineQuantity
          &lt;/td&gt;
          &lt;td class="EstimateRateData"&gt;
              @_oEstimateDetails.EstimateLineRate
          &lt;/td&gt;
          &lt;td class="EstimateLineTotalData"&gt;
              @(_oEstimateDetails.EstimateLineQuantity * _oEstimateDetails.EstimateLineRate)
          &lt;/td&gt;
          &lt;/tr&gt;
          _recordCount = _recordCount + 1;
      }
  }
  </code></pre>
  
  <p>Since this is my 5th attempt to figure this out, I am about to pull my hair out. Any assistance would be most appreciative.</p>