Umbraco 7 test for Odd and Even rows in a loop to display differenrt coloured rows or sections

The snippet example below shows one way of testing for Odd and Even in an umbraco foreach loop.

The result is to list out odd and even background colours, suach as in bootstrap sections.

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    var count = 0;   
    var colourClass = "";


    @foreach(var childPage in Umbraco.Content(1067).Children().Where("NodeTypeAlias == \"newPageSection\""))
         if(count% 2 == 0)


  <div class="content-block content-block-@colourClass">

// DO some stuff



Popular posts from this blog

Umbraco Razor Sort Nodes Ascending or Descending

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco

Umbraco - Reset the Admin Password via SQL Server