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 7 - C# Razor - Passing a parameter variable from a Template to a Partial View.

Umbraco 7 Hide a page from Navigation or Sub Navigation with umbracoNaviHide using Razor in a template or partial view

Umbraco Razor Sort Nodes Ascending or Descending