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 252081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:38:54+00:00 2026-05-11T21:38:54+00:00

In a master-page, how can I know, which controller I am currently using? Is

  • 0

In a master-page, how can I know, which controller I am currently using? Is there some kind of context-object, that can give me that sort of information?

Standard menu

<ul>
<li>Fire</li>
<li>Ice</li>
<li>Water</li>
</ul>

Menu if I am in the water-controller

<ul>
<li>Fire</li>
<li>Ice</li>
<li class="selected">Water</li>
</ul>

If I have a menu in my Site.master, where each menu-item refers to a different controller, how can I highlight each menu-item depending on, which controller I am currently in?

I know I can get the url from request.Servervariables and then work some string-magic, but there must be a better way – some kind of context-object?

  • 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-11T21:38:54+00:00Added an answer on May 11, 2026 at 9:38 pm

    Here are two helper methods I use for checking if its the current controller or even current action. The you can use the helpers to determine whether to add class=”selected” or not.

    public static bool IsCurrentController(this HtmlHelper helper, 
                                           string controllerName)
    {
        string currentControllerName = (string)helper.ViewContext.RouteData.
                                       Values["controller"];
    
        if (currentControllerName.Equals(controllerName,
            StringComparison.CurrentCultureIgnoreCase))
        {
           return true;
        }
    
        return false;
    }
    
    public static bool IsCurrentAction(this HtmlHelper helper, string actionName, 
                                       string controllerName)
    {
        string currentControllerName = (string)helper.ViewContext.RouteData
                                       .Values["controller"];
        string currentActionName = (string)helper.ViewContext.RouteData
                                   .Values["action"];
    
        if (currentControllerName.Equals(controllerName,
            StringComparison.CurrentCultureIgnoreCase) && 
            currentActionName.Equals(actionName, 
                                     StringComparison.CurrentCultureIgnoreCase))
        {
            return true;
        }
    
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can the elements of the Master Page be accessed from the Content Page? Lets
I have a master page that contains an ASP.NET server side Menu control (System.Web.UI.WebControls.Menu)
I have a master page which all my views inherit from. The issue I
Can I use Update panel in masterpage to wrap nested pages so that when
My master page contains a list as shown here. What I'd like to do
I have a master page, with a help link in the top menu. This
If the Master Page and child aspx page are in different folders, when the
The boss wants the master page's menu to look nicer. I generated my gradient
I have a MasterPage, with my Usercontrol inside a div. I can set visible=false
So, from my experience, masterpages sometimes can lag when you do updates. This is

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.