ASP.NET MVC 4 View ( Razor ) + foreach + if 方法

 
ASP.NET MVC 4 View ( Razor ) + foreach + if 方法
 

 
   @{
      … …
 
      int i = 0;
   }
 
   … …
 
   @foreach (var item in Model.promotioncategory)
   {
      if (i % 3 == 0)
      {
         @Html.Raw("<div class='row'>")
      }
 
      <div class="col-md-4">
         <div style="height:170px;">
            <h2 style="cursor:default;">@item.Category_Header</h2>
            <p style="font-size:13px; cursor:default;">@item.Category_SDescription</p>
         </div>
         <p><a class="btn btn-default" href="/Content/Category/@item.Category_ID/">更多 »</a></p>
      </div>
 
      if (i % 3 == 2)
      {
         @Html.Raw("</div>")
      }
 
      i++;
   }