Copied to clipboard

Flag this post as spam?

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


  • Kev 16 posts 67 karma points
    Nov 11, 2013 @ 20:59
    Kev
    0

    Can you have active classes based on QueryStrings

    Is it possible to add an active class to a link based on a querystring?

    So in a normal navigation you might have something like:

    @foreach (var page in root.DescendantsOrSelf().Where("Visible")) {
        <a href="@page.Url" class="@page.IsEqual(Model, "active", "")" >@page.Name</a>
    }
    

    Could I do something similar, but based on a queryString – in this case eventDistance:

    <a href="@Model.Url?eventDistance=@distName" class="distance-link">@distName</a>
    

    The QueryString could match:

    • Novice
    • Sprint
    • Standard

    Thanks in advance.

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Nov 11, 2013 @ 21:23
    Anders Bjerner
    100

    Something like this should do it ;)

    @(Request.QueryString["something"] == "something" ? "yeah" : "noes")
    
  • Kev 16 posts 67 karma points
    Nov 11, 2013 @ 22:24
    Kev
    0

    Brilliant – thank you so much :)

Please Sign in or register to post replies

Write your reply to:

Draft