How to style alternating rows in asp.net mvc
- by YeahStu
I am using a <% foreach ...% loop to list a collection of items on my website.
I want to add a different background color for the style of alternating rows in my list. I have found a way to do this but I am not satisfied with it as it seems like a hack.
Here is what I have done to solve it so far:
<table>
<% int counter = 0;
foreach (var item in Model)
{
counter++;
if (counter % 2 == 0)
{
%>
<tr class="colorfull">
<% }
else
{ %>
<tr>
<% } %>
...
Is there a best practice that I am missing that people are using for this scenario in ASP.NET MVC?