Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rayyan 46 posts 237 karma points
    Mar 25, 2019 @ 08:46
    Rayyan
    0

    How to add (dropdown-toggle) ONLY for items that has sub items

    @{ var selection = Model.Root().Children.Where(x => x.IsVisible()).ToArray(); }
    
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
      @if (selection.Length > 0)
    {
        <ul class="navbar-nav mr-auto">
             @foreach (var item in selection)
            {    
          <li class="col l1 nav-item dropdown @(item.IsAncestorOrSelf(Model) ? "active" : null)">
            <a class="nav-link dropdown-toggle" href="@item.Url" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              @item.Name
            </a>
             @if (item.Children.Any(x => x.IsVisible()))
            {
            <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                 @foreach (var subMenu in item.Children.Where(x => x.IsVisible()))
         {
              <li class="dropdown-item">
                <a href="@subMenu.Url">@subMenu.Name</a>
              </li>
              }
            </ul>
            }
          </li>
          }
        </ul>
        }
      </div>
    </nav>
    
  • AddWeb Solution Pvt. Ltd 34 posts 187 karma points
    Mar 25, 2019 @ 10:47
    AddWeb Solution Pvt. Ltd
    0

    Have you tried debugging your way through? Have you checked the generated HTML source to see if there actually are items in the dropdown-menu ul?

    Which Umbraco version are you using? Looks like 7.x - so there are much easier ways to do some of what you do. Like @CurrentPage.Site() to get root node.

    You are including both bootstrap.js and bootstrap.min.js, that might mess things up, as well as including what looks like two versions of jQuery?

    Also, you are including (the jquery-2.2.0.js) jQuery after bootstrap.js, that might also cause problems.

    Please Refer this link for more understanding :

    https://stackoverflow.com/questions/36014354/dropdown-menu-in-umbraco-cms

Please Sign in or register to post replies

Write your reply to:

Draft