I have an asp.net-mvc website. In my view model, I have a collection of cars that I want to display on an HTML table.
I want to show 5 cars per line, so I started something like this:
<table> @foreach (var car in Model.Cars) { if (counter == 0) { <tr> } <td>@car.Name</td> counter++; if (counter == 5) { </tr> } } </table>
I feel that the code above is a bit hacked, and also, if I have 7 machines, should I put 3 empty <td> in the last line or disable it (again, more hacker code)?
I wanted to know if there was a cleaner way in asp.net-mvc to display a collection in a table with a certain number of records in a table in a row.
leora source share