title: Getting index value on razor foreach
body: <p>I'm iterating a <code>List&lt;T&gt;</code> in a razor foreach loop in my view which renders a partial. In the partial I'm rendering a single record for which I want to have 4 in a row in my view. I have a css class for the two end columns so need to determine in the partial whether the call is the 1st or the 4th record. What is the best way of identifying this in my partial to output the correct code?</p>
  
  <p>This is my main page which contains the loop:</p>
  
  <pre><code>@foreach (var myItem in Model.Members){
  
          //if i = 1
          &lt;div class="grid_20"&gt;
          &lt;!-- Start Row --&gt;
  
          //is there someway to get in for i = 1 to 4 and pass to partial?
          @Html.Partial("nameOfPartial", Model)
  
          //if i = 4 then output below and reset i to 1
          &lt;div class="clear"&gt;&lt;/div&gt;
          &lt;!-- End Row --&gt;
          &lt;/div&gt;
  
  }
  </code></pre>
  
  <p>I figure I can create a int that I can update on each pass and render the text no problem here but it's passing the integer value into my partial I'm more concerned about. Unless there's a better way.</p>
  
  <p>Here is my partial:</p>
  
  <pre><code>@{
  switch()
  case 1:
          &lt;text&gt;
          &lt;div class="grid_4 alpha"&gt;
          &lt;/text&gt;
  break;
  case 4:
          &lt;text&gt;
          &lt;div class="grid_4 omega"&gt;
          &lt;/text&gt;
  break;
  default:
          &lt;text&gt;
          &lt;div class="grid_4"&gt;
          &lt;/text&gt;
  break;
  }
  
          &lt;img src="Content/960-grid/spacer.gif" style="width:130px; height:160px; background-color:#fff; border:10px solid #d3d3d3;" /&gt;
          &lt;p&gt;&lt;a href="member-card.html"&gt;@Model.Name&lt;/a&gt;&lt;br/&gt;
          @Model.Job&lt;br/&gt;
          @Model.Location&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Not sure if I'm having a blonde day today and this is frightfully easy but I just can't think of the best way to pass the int value in. Hope someone can help.</p>