Hello,
I am trying to create a two level navigation for my site. I have changed the order of the code and get various error messages the latest being error -
CS1928: 'System.Collections.Generic.IEnumerable ... does not contain a definition for 'Any'
I also get the name secondLevel does not exist in the current context even though the var is above the code block where it will be used.
I'm very confused if someone could explain why the code below is not working I would be very grateful.
The code from the Template linking to this partial is @Html.Partial("V6NavigationTopLevel-2")
Thank you
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
Displays child pages below the root page of a standard website.
*@
@{
@* Get the root of the website *@
var root = Umbraco.AssignedContentItem.AncestorOrSelf(1);
var firstLevel = root.Children.Where("Visible");
@* dispaly first level *@
foreach(var sectionPage in firstLevel)
{
<ul role="navigation" aria-label="Primary" class="nav navbar-nav">
<li>
<a href="@sectionPage.Url">@sectionPage.Name</a>
@* display secon level *@
@if (sectionPage.Children.Any("Visible"))
{
var secondLevel = sectionPage.Children.Where("Visible");
<ul aria-label="Secondary" class="">
@foreach (var subSection in secondLevel)
{
@* display subSection here *@
<li>
<a href="@subSection.Url">@subSection.Name</a>
</li>
}
</ul>
}
</li>
</ul>
}
Hi,
I have the solution - you can't place the Visible in the any() it needs to go in the where() and then you activate the boolean any. So the correct code is: -
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
Displays child pages below the root page of a standard website.
*@
@{
@* Get the root of the website *@
var root = Umbraco.AssignedContentItem.AncestorOrSelf(1);
var firstLevel = root.Children.Where("Visible");
@* Second level *@
foreach(var sectionPage in firstLevel)
{
<ul role="navigation" aria-label="Primary" class="nav navbar-nav">
<li>
<a href="@sectionPage.Url">@sectionPage.Name</a>
@if (sectionPage.Children.Where("Visible").Any())
{
var secondLevel = sectionPage.Children.Where("Visible");
<ul aria-label="Secondary" class="">
@foreach (var subSection in secondLevel)
{
// display subSection here
<li>
<a href="@subSection.Url">@subSection.Name</a>
</li>
}
</ul>
}
</li>
</ul>
}
Site navigation
Hello, I am trying to create a two level navigation for my site. I have changed the order of the code and get various error messages the latest being error -
CS1928: 'System.Collections.Generic.IEnumerable ... does not contain a definition for 'Any'
I also get the name secondLevel does not exist in the current context even though the var is above the code block where it will be used.
I'm very confused if someone could explain why the code below is not working I would be very grateful.
The code from the Template linking to this partial is @Html.Partial("V6NavigationTopLevel-2")
Thank you
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@* Displays child pages below the root page of a standard website. *@
@{
}
Hi, I have the solution - you can't place the Visible in the any() it needs to go in the where() and then you activate the boolean any. So the correct code is: -
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@* Displays child pages below the root page of a standard website. *@
@{
}
Thank you, I hope this is useful for others :)
is working on a reply...