I have a generic list of objects, for example: List<Photo> and want to convert this to something I can use on an MVC view.
In the form (basic example):
<% foreach (var row in PhotoList) { %>
// Render Matrix (using photo properties)
<tr>
<% foreach(photo in row) { %>
<td><%=photo.Name%></td>
<% } %>
</tr>
<% } %>
I have thought of doing this manually, using something like List<List<Photo>>(), but is there a nifty way of doing this using LINQ? Supplying the number of columns, rows and page a paged Matrix Display, or other better ideas.
You could create a matrix using
GroupBy()given the number of columnsxyou want:The result is a
List<List<Photo>>withxphotos in each inner list. You should then just be able to use two foreach loops to render them (as in your example).