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 3074 posts 13632 karma points MVP 11x 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 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 29, 2014 @ 17:48
    Jeavon Leopold
    0

    Awesome!

Please Sign in or register to post replies

Write your reply to:

Draft