Razor script to insert </div> and <br /> for every 3 items in a row
Hi
I need a Razor script to insert </div> and <br /> everytime there is 3 items in a row. Everything works when there is 3 or less items in the row, but if there are more than 3 itmes the layout looks wrong.
It is the closing </div> for the <div class="row"> that i need every 3 item.
My code looks like this (It is the 5 last lines of code that does not work):
@{ @*Get the root of the website *@ var root = Model.AncestorOrSelf(3); } <div class="row"> @foreach (var page in root.Children.Where("Visible")) { <div class="span3"> <div class="service-overview"> <h5><a href="@page.Url">@page.headerMain</a></h5> <p>@(Library.Truncate(Library.StripHtml(page.mainText), 60, true))</p> <img src="@page.image" alt="" /> <div class="service-overview-overlay">+</div> </div><!-- end .service-overview --> </div><!-- end .span3 --> }
The InGroupsOf() method is very easy to use for tasks like this. I have pasted the example from the documentation here:
@* return in groups of 3 *@ @foreach(var group in Model.Children.InGroupsOf(3)){ <div class="row"> @foreach(var item in group){ <div>@item.Name</div> } </div> }
Razor script to insert </div> and <br /> for every 3 items in a row
Hi
I need a Razor script to insert </div> and <br /> everytime there is 3 items in a row. Everything works when there is 3 or less items in the row, but if there are more than 3 itmes the layout looks wrong.
It is the closing </div> for the <div class="row"> that i need every 3 item.
My code looks like this (It is the 5 last lines of code that does not work):
Thanks in advance!
Kind regards
René
The InGroupsOf() method is very easy to use for tasks like this. I have pasted the example from the documentation here:
/Carsten
Hi Carsten
Great now it's working. Thanks a lot. :-)
My code looks like this now:
/René
is working on a reply...