Using IDisposable to stripe a table What are your thoughts on using an IDisposable to stripe an HTML table like so? It's a blatant abuse of IDisposable but this allows you to use the counter in a using(){} block which gives you a clear block in the markup.

public class StripeCounter : IDisposable
{
    private string cssClass = "stripe";

    private int counter = 0;

    public StripeCounter(){}

    public StripeCounter(string cssClass)
    {
        this.cssClass = cssClass;
    }

    public MvcHtmlString Stripe()
    {
        return MvcHtmlString.Create(counter++ % 2 == 1 ? cssClass : string.Empty);
    }

    public void Dispose() { }
}


And then the markup

@using (var counter = new StripeCounter())
{
    foreach (var item in Model)
    {
    &lt;tr class="@counter.Stripe()"&gt;
        &lt;td&gt;
            ...
        &lt;/td&gt;
       ...
    &lt;/tr&gt;
    }
}


Regarding comments on using JavaScript to stripe the table:

JavaScript is for behaviour and the striped rows of a table aren't behaviour; they are style, so while it is possible to do so on the client, it seem to me to be something that should be done on the server. For example, if someone has scripts disabled, they would still see the CSS striping, but not JavaScript striping.
Don't do the striping on the server. Don't do the striping with JavaScript. Since it's styling, do the striping with CSS.