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

The Archive Base Latest Questions

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

My requirements are to be able to map a custom controller but have it

  • 0

My requirements are to be able to map a custom controller but have it built in that only one action can ever be called. So instead of this:

 context.MapRoute(
    "RouteName",
    "{controller}/{id}",
    new {
        controller = "MyCustomController",
        action = "DefaultAction", <- I want to remove this.
        id = UrlParameter.Optional
    }
 );

I want to do this:

 context.MapRoute(
    "RouteName",
    "{controller}/{id}",
    new {
        controller = "MyCustomController",
        id = UrlParameter.Optional
    }
 );

And to have it call “DefaultController” by well…default without having to specify declare it in the defaults argument of MapRoute.

Any help?

  • 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-31T02:02:27+00:00Added an answer on May 31, 2026 at 2:02 am

    You can’t do that. Your url doesn’t contain an {action} token. This means that you absolutely should specify which action you want to invoke in the default values.

    Put yourself on the place of the routing engine. You see the following request: Home/123. You look at the route definition and you see {controller}/{id}.

    Great => now you know that you could instantiate the HomeController but that’s all you know if an action is not specified as a default value. You have no idea which action to invoke on this HomeController and the story ends here.

    You throw the following exception to the developer to inform him about the problem with his code:

    The RouteData must contain an item named ‘action’ with a non-empty string value.


    UPDATE:

    You could write a custom extension method that will allow you to omit the default action in the declaration but it will add it behind the scenes:

    public static class RouteExtensions
    {
        public static Route MyMapRoute(this RouteCollection routes, string name, string url, object defaults)
        {
            var defaultValues = new RouteValueDictionary(defaults);
            if (!defaultValues.ContainsKey("action"))
            {
                defaultValues["action"] = "index";
            }
            var route = new Route(url, new MvcRouteHandler())
            {
                Defaults =  defaultValues,
                Constraints = new RouteValueDictionary(),
                DataTokens = new RouteValueDictionary()
            };
            routes.Add(name, route);
            return route;
        }
    }
    

    and then:

    routes.MyMapRoute(
        "RouteName",
        "{controller}/{id}",
        new { controller = "MyCustomController", id = UrlParameter.Optional }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Requirements : I have a table of several thousand questions. Users can view these
Premise : The requirements for an upcoming project include the fact that no one
The requirements I have have to do with being able to print routes between
We are designing a system and one of our requirements is to be able
Requirements: Must be able to use C strings as well as C++ strings Fast
I have a requirement to be able to provide a flex component in English
I have a somewhat weird requirement to be able to listen to a number
I have a requirement to be be able to embed scanned tiff images into
We have a requirement for people to be able to look at documents people
Requirements: free, preferably open-source implemented in one of the .NET managed langs Google found

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.