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

  • Home
  • SEARCH
  • 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, here's the scenario. I have a utility that processes tons of records, and
okay so i have a log in button on the top of my site
Okay, I have a question guys. I want to remote upload (copy an image
Okay, we know that the following two lines are equivalent - (0 == i)
Okay, so, here's what the problem is. I'm creating a flash site with each
Okay, here is my situation. I have a page, index.php, which is the mainsite
Okay, I have a page on and on this page I have an iframe.
Alright...I've given the site a fair search and have read over many posts about
i am currently working on a approach to parse a site that contains datas
Okay, the question could probably a phrased better. I have a string. 2008 apple

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.