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

    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>
      <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">
             @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>
  • AddWeb Solution Pvt. Ltd 43 posts 197 karma points
    Mar 25, 2019 @ 10:47
    AddWeb Solution Pvt. Ltd

    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 :

Please Sign in or register to post replies

Write your reply to: