Multi-Level Dropdown Navigation

This example demonstrates implementing dropdown menus with nested child items.

Data Type Configuration

For multi-level navigation, configure your Data Type:

Setting
Value

Maximum Depth

3 (or as needed)

Allow Text Items

Yes (for section headers)

Allow Images

Optional

Allow Custom Classes

Yes

Basic Dropdown Implementation

Recursive Partial View

Create a partial view that renders items recursively.

_NavigationItem.cshtml

@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>

_Navigation.cshtml

CSS for Dropdowns

JavaScript-Enhanced Dropdown

For better accessibility and mobile support, add JavaScript:

Using the Menu Builder Service

For more control over depth and processing:

Animated Dropdowns

Add smooth animations with CSS:

Use text items as section headers within dropdowns:

Complete Example with View Component

Usage

Last updated

Was this helpful?