Multi-Level Dropdown Navigation
This example demonstrates implementing dropdown menus with nested child items.
Data Type Configuration
Setting
Value
Basic Dropdown Implementation
Recursive Partial View
@model Umbraco.Community.UmbNav.Core.Models.UmbNavItem
@using Umbraco.Community.UmbNav.Core.Models
@using Umbraco.Community.UmbNav.Core.Enums
@{
var hasChildren = Model.Children?.Any() == true;
var currentPage = ViewData["CurrentPage"] as Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent;
var isActive = Model.IsActive(currentPage, includeDescendants: true);
}
<li class="nav-item @(hasChildren ? "has-dropdown" : "") @(isActive ? "active" : "")">
@if (Model.ItemType == UmbNavItemType.Title)
{
<span class="nav-label">@Model.Name</span>
}
else
{
<a href="@Model.Url()"
class="nav-link @(isActive ? "active" : "") @Model.CustomClasses"
target="@Model.Target"
rel="@Model.Noopener @Model.Noreferrer"
@(hasChildren ? "aria-haspopup=true aria-expanded=false" : "")>
@Model.Name
@if (hasChildren)
{
<span class="dropdown-arrow" aria-hidden="true"></span>
}
</a>
}
@if (hasChildren)
{
<ul class="dropdown-menu" role="menu">
@foreach (var child in Model.Children!)
{
@await Html.PartialAsync("_NavigationItem", child, ViewData)
}
</ul>
}
</li>CSS for Dropdowns
JavaScript-Enhanced Dropdown
Using the Menu Builder Service
Animated Dropdowns
Dropdown with Section Headers
Complete Example with View Component
DropdownNavigationViewComponent.cs
Usage
Last updated
Was this helpful?