@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var selection = CurrentPage.AncestorOrSelf().Children.Where("showInFooter").OrderBy("Name");
int max = 8;
}
<ul>
@for (int i = 0; i < selection.Count(); i++)
{
var page = selection[i];
<li>@page.Name</li>
}
</ul>
I also know I can do it this way:
<ul>
@foreach (var page in selection) {
<li>@page.Name</li>
}
</ul>
but what I am trying to achieve is when i == max, I want to split the UL into a new list. Problem is, Razor renders the following error because its seeing unexpected closing of UL and opening of UL that is not in the { } block.
My code block:
<ul>
@for (int i = 0; i < selection.Count(); i++)
{
var page = selection[i];
if (i == max)
{
</ul>
<ul>
}
<li>@page.Name</li>
}
</ul>
Thanks Carsten. That did work and alot more elegant than my version
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var selection = CurrentPage.AncestorOrSelf().Children.Where("showInFooter").OrderBy("Name");
int max = 8;
string HtmlBlock = "</ul></div><div class=\"site-map\"><ul>";
System.Web.HtmlString html = new HtmlString(HtmlBlock);
}
<div class="site-map">
<ul>
@for (int i = 0; i < selection.Count(); i++)
{
var page = selection[i];
if (i == max)
{
@html
}
<li>@page.Name</li>
}
</ul>
</div>
Splitting a UL list in Razor
Please see the working code below:
I also know I can do it this way:
but what I am trying to achieve is when i == max, I want to split the UL into a new list. Problem is, Razor renders the following error because its seeing unexpected closing of UL and opening of UL that is not in the { } block.
My code block:
Many thanks!
Phillip
Hi Phillip,
I believe the easiest way to achieve what you want is to use the InGroupsOf() method:
I haven't tested the code, but it should be something like this.
/Carsten
Thanks Carsten. That did work and alot more elegant than my version
Phillip
is working on a reply...