Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
The following code works for me in rendering a single level mega menu with Models Builder...
@{ if (Model.HasValue("MytopNav")) { <ul> @foreach (var item in Model.MytopNav) { <li class="dropdown"> @item.Title @*check for child links here*@ </li> } </ul> } }
But if any of my parent level li's have child links, how do I check for that and add it to this logic?
Hi blackhawk,
You can just check for children in each loop and then do another loop inside, something like this:
@{ if (Model.Content.HasValue("MytopNav")) { <ul> @foreach (var item in Model.MyTopNav) { <li class="dropdown"> @item.Title @*check for child links here*@ @if (item.Children.Any()) { <ul> @foreach (var child in item.Children) { <li>@child.Title</li> } </ul> } </li> } </ul> } }
Thanks for the help! I only had to change Children() to Children.
Ah, so close! I had thought it was that actually but my Visual Studio told me otherwise. Strange, updated my answer to match however.
How to render third and fourth levels for MegaNav with Models Builder?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to render a 2nd level for MegaNav with Models Builder
The following code works for me in rendering a single level mega menu with Models Builder...
But if any of my parent level li's have child links, how do I check for that and add it to this logic?
Hi blackhawk,
You can just check for children in each loop and then do another loop inside, something like this:
Thanks for the help! I only had to change Children() to Children.
Ah, so close! I had thought it was that actually but my Visual Studio told me otherwise. Strange, updated my answer to match however.
How to render third and fourth levels for MegaNav with Models Builder?
is working on a reply...