Copied to clipboard

Flag this post as spam?

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


  • arf123 4 posts 34 karma points
    Jul 29, 2014 @ 16:51
    arf123
    0

    How do I add an active class to my <li> when the current page is active?

     @{
                        var rootPages = Umbraco.ContentAtRoot().Where("showOnPrimaryNavigation = true");
    
                        if (rootPages.Count() != 0)                     
                        {
                            <ul class="nav navbar-nav navbar-right">
                               @foreach (var rootPage in rootPages)
                               {
                                <li class="@(CurrentPage.IsAncestorOrSelf(Model) ? "active" : null)">
                                    <a href="@rootPage.Url">@rootPage.navigationText</a>
                                </li>
                               }                                
                            </ul>                          
                        }
                   }          
    
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jul 29, 2014 @ 16:55
    Jeavon Leopold
    100

    Welcome to Our!

    How about this?

    <li class="@(rootPage.IsAncestorOrSelf(CurrentPage) ? "active" : null)">
    
  • arf123 4 posts 34 karma points
    Jul 29, 2014 @ 16:58
    arf123
    0

    Thanks man, that did the trick!!!

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jul 29, 2014 @ 17:48
    Jeavon Leopold
    0

    Awesome!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies