Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6015815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:53:26+00:00 2026-05-23T02:53:26+00:00

Okay, my site is www.kristianbak.com . I have a css class called activebutton .

  • 0

Okay, my site is http://www.kristianbak.com.

I have a css class called activebutton. I want that to change whenever another View is active. Currently it’s merely hard-coded in the HTML (sitemaster).

Anyone with a good idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:53:27+00:00Added an answer on May 23, 2026 at 2:53 am

    You could test the current action and if it matches apply a CSS class:

    <% if (ViewContext.RouteData.GetRequiredString("action") == "About") { %>
        ... highlight here
    <% } %>
    

    Even better I would write a HTML helper to generate the menu:

    public static MvcHtmlString MenuItem(
        this HtmlHelper htmlHelper, 
        string text,
        string action, 
        string controller
    )
    {
        var li = new TagBuilder("li");
        var routeData = htmlHelper.ViewContext.RouteData;
        var currentAction = routeData.GetRequiredString("action");
        var currentController = routeData.GetRequiredString("controller");
        if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) &&
            string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase))
        {
            li.AddCssClass("active");
        }
        li.InnerHtml = htmlHelper.ActionLink(text, action, controller).ToHtmlString();
        return MvcHtmlString.Create(li.ToString());
    }
    

    and then use it like this:

    <ul>
        <%= Html.MenuItem("Home", "Home", "Home") %>
        <%= Html.MenuItem("About Me", "About", "Home") %>
        <%= Html.MenuItem("My Work", "Work", "Home") %>
        <%= Html.MenuItem("Blog", "Index", "Blog") %>
        ...
    </ul>
    

    This will add the active class to the anchor if the current request matches the action and controller of the link.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay.. so basically, say we have a link: $url = http://www.site.com/index.php?sub=Mawson&state=QLD&cat=4&page=2&sort=z; Basically, I need
I have a URL that is like the following: http://www.example.com/client/project/subdirectory/value/ I would like like
Okay, at the moment on my site I have a feature that blacklists words,
Okay, so i have the following html added to a site using javascript/greasemonkey. (just
okay so i have a log in button on the top of my site
Okay so I have this web site search script and I'm trying to count
I have a section of a website that sets a session variable. On another
Okay im creating a mobile site and I have a page of images and
Okay, so I have searched this site and found many tutorials on how to
Okay, so I want to make a polling site but it doesn't work like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.