In MVC3, how do you create alternating row colors on a @foreach list when using the Razor view engine?
@foreach (var item in Model) {
<tr>
<td>@item.DisplayName</td>
<td>@item.Currency</td>
<td>@String.Format("{0:dd/MM/yyyy}", item.CreatedOn)</td>
<td>@String.Format("{0:g}", item.CreatedBy)</td>
<td>@Html.ActionLink("Edit", "Edit", new { id = item.Id })</td>
</tr>
}
How about something like this?
A solution i use to support IE8 (corporate browser, not by choice) was to combine the_lotus's solution with a jquery solution
Since IE8 doesnt support
nth-child()
use this cssAnd use jQuery to do this:
Original: http://15daysofjquery.com/table-striping-made-easy/5/ Author: Jack Born jQuery Zebra_Striping_Made_Easy
=============== Java script ===================
================= css =================
=============== HTML ===============
With ASP.NET MVC 3 and the new @helper syntax, there is a neater way to handle this.
First add this @helper method:
Then just add the call to the helper in your
<TR>
elementwhat about using the jQuery DataTable plugin. i used it on an MVC2 application i developed.
http://www.datatables.net/