I have this razor script which generates 2 levels of navigation from the current page. It seems to be working fine until I wrap the second foreach statement in a <ul>, then it throws an error saying the variable doesn't exist in the current context.
Any ideas?
@inherits umbraco.MacroEngines.DynamicNodeContext
@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@ @if (Model.Parent.Children.Where("Visible").Any()) { <nav> <ul> @* For each child page under the root node, where the property umbracoNaviHide is not True *@ @foreach (var childPage in Model.Parent.Children.Where("Visible")) { <li> <a href="@childPage.Url"> @if(@childPage.HasProperty("navigationDisplayName") && @childPage.GetProperty("navigationDisplayName").Value != String.Empty) { @childPage.navigationDisplayName; } else { @childPage.Name; } </a> @if (childPage.Children.Where("Visible").Count() > 0) { <ul> foreach (var childChildPage in childPage.Children.Where("Visible")) { <li> <a href="@childChildPage.Url"> @if(@childChildPage.HasProperty("navigationDisplayName") && @childChildPage.GetProperty("navigationDisplayName").Value != String.Empty) { @childChildPage.navigationDisplayName; } else { @childChildPage.Name; } </a> </li> } </ul> } </li> } </ul> </nav> }
Error when inserting <ul>
I have this razor script which generates 2 levels of navigation from the current page. It seems to be working fine until I wrap the second foreach statement in a <ul>, then it throws an error saying the variable doesn't exist in the current context.
Any ideas?
Hi Amir,
You need to add the @ sign before your foreach loop
@foreach (var childChildPage in childPage.Children.Where("Visible")
Hi Amir,
You need to add the @ sign before your foreach loop
@foreach (var childChildPage in childPage.Children.Where("Visible")
Thanks Fuji!
is working on a reply...