Razor - using foreach, insert html every nth item
Not sure if your wanting to increment the Item
number (or if @item.Name
actually contains the incremented number), but the following code will increment both the class name (a new div
every 4th iteration) and the item number.
@{ var t = 0; var i = 1; }
<div class="tab-@t">
@foreach (var item in Model.Items)
{
<a>Item @i</a> // this may be just @item.Name?
if (i % 4 == 0)
{
t++;
@:</div><div class="tab-"@t>
}
i++;
}
</div>