this is the latest mvc 5.2
here is the helper from code used from a forgotten blog years ago
public static void SeriesSplitter<T>(this System.Web.Mvc.HtmlHelper htmlHelper, IEnumerable<T> items,
int itemsBeforeSplit, Action<T> template, Action seriesSplitter)
{
if (items == null)
return;
if (items.Count() == 0)
return;
var i = 0;
foreach (var item in items)
{
if (i != 0 && i % itemsBeforeSplit == 0)
seriesSplitter();
template(item);
i++;
}
}
I use it like this
<table class="public-photo" >
<tr class="public-photo">
<% Html.SeriesSplitter(Model.Photos, 6, item => { %>
<td class="public-photo">
<a href="/Anon/DisplayPublicPhoto/?filename=<%=item.PublicFileName%>" class="public-photo" >
<%if(Model.HighRes == true){%>
<img src="/t2/<%=item.PublicFileName%>" id="<%=item.PublicFileName%>" class="public-photo" alt="thumbnail" width="140" height="105" />
<%}
else
{%>
<img src="/t/<%=item.PublicFileName%>" id="<%=item.PublicFileName%>" class="public-photo" alt="thumbnail" width="140" height="105" />
<% } %>
</a>
<a href="#" class="ReportPhoto" id="<%=item.PhotoID%>">Report this</a>
</td>
<%}, () => { %>
</tr>
<tr>
<% }); %>
</tr>
</table>
No problems in aspx but razor seems to choke on the last part of the action parameter where html code is interpersed with code. for razor I converted it to the correct syntax EDIT Razor code
<table class="public-photo">
<tr class="public-photo">
@Html.SeriesSplitter(Model.Photos, 6, icetem =>
{
@<td class="public-photo">
<a href="/Anon/DisplayPublicPhoto/[email protected] " class="public-photo">
@if (Model.HighRes == true)
{
<img src="/t2/@icetem.PublicFileName" id="@icetem.PublicFileName" class="public-photo" alt="thumbnail" width="140" height="105" />
}
else
{
<img src="/t/@icetem.PublicFileName" id="@icetem.PublicFileName" class="public-photo" alt="thumbnail" width="140" height="105" />
}
</a>
<a href="#" class="ReportPhoto" id="@icetem.PhotoID">Report this</a>
</td>;
},
() => {
//</tr>
// <tr>
});
</tr>
</table>
the error is CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement