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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:03:27+00:00 2026-06-07T06:03:27+00:00

After I register a route, how can I retrieve controller and action name what

  • 0

After I register a route, how can I retrieve controller and action name what belongs to the specified route name?

For example if I register this route:

routes.MapRoute("Category",
                "C/{id}/{urlText}",
                new { controller = "Catalog", action = "ProductListByCategoryId" }
);

I want to retrieve the controller name “Catalog” and the action name “ProductListByCategoryId” by the route name parameter “Category”.

I need this for a html helper:

public static MvcHtmlString MenuLink(this HtmlHelper helper,
                                string name,
                                string routeName,
                                object routeValues)
{
    string currentAction = helper.ViewContext.RouteData.GetRequiredString("action");
    string currentController = helper.ViewContext.RouteData.GetRequiredString("controller");
    object currentId = helper.ViewContext.RouteData.Values["id"];

    string actionName = ""; //This is what I want to specify
    string controllerName = "";  //This is what I want to specify
    var propertyInfo = routeValues.GetType().GetProperty("id");
    var id = propertyInfo.GetValue(routeValues, null);

    if (actionName == currentAction &&
        controllerName == currentController &&
        id == currentId)
    {
        return helper.RouteLink(name, routeName, routeValues, new { @class = "active" });
    }
    else
    {
        return helper.RouteLink(name, routeName, routeValues, new { @class = "active" });
    }

}
  • 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-06-07T06:03:28+00:00Added an answer on June 7, 2026 at 6:03 am

    You can’t do this given only a route name. The reason for that is that a route could match for multiple controllers and actions. What you could do is to retrieve the current controller and action from the HttpContext:

    RouteData rd = HttpContext.Request.RequestContext.RouteData;
    string currentController = rd.GetRequiredString("controller");
    string currentAction = rd.GetRequiredString("action");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On this page: http://nerddinnerbook.s3.amazonaws.com/Part4.htm After the controller is added, I can browse to http://localhost:xxxx/dinners
after debbuging i am getting following url of my webproject: http://localhost:54594/Home/Home /Home-Controller/Home-Action http://localhost:54594/AboutUs/AboutUs /AboutUs-Controller/AboutUs-Action
I'm trying to figure out how to handle my routes and controller. After a
i have created one login and register view in that view after login user
After deploying WCF server (svc) on my Server, I have got this message when
This is my application's current workflow for user registration. register form ( GET /register
The REST project works fine, this can be accessed through this address: http://localhost:8525/Device/Login?deviceID=testid&password=a&serialNum=testserial I
If you wanted to alter the way that routes were processed can you do
I'm trying to figure out how I can set up my routes so that
I have no idea why this error is occurring after debugging the project even

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.