Razor IsOdd for row building logic skipping last node if odd number
Hi!
I have this logic to build some rows / columns for a split column layout. It seems that the logic skips the last one if there is an odd number in the total collection. Is there an easy way to check if the total number is odd and change the logic?
Thanks, Amir
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var selection= CurrentPage.Awards.Where("Visible"); var totalChildren = @selection.Count();
Razor IsOdd for row building logic skipping last node if odd number
Hi!
I have this logic to build some rows / columns for a split column layout. It seems that the logic skips the last one if there is an odd number in the total collection. Is there an easy way to check if the total number is odd and change the logic?
Thanks,
Amir
Here we go! int rows = totalChildren / 2 + Math.Sign(totalChildren % 2);
From Rodion's answer here: http://our.umbraco.org/forum/developers/razor/29168-Rounding-up-a-variable
-Amir
is working on a reply...