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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:11:22+00:00 2026-06-18T06:11:22+00:00

I recently got burned by the fact that these two MVC4 routes, apparently, function

  • 0

I recently got burned by the fact that these two MVC4 routes, apparently, function differently. I was wondering if someone could highlight what’s going on so I could better understand.

routes.MapRoute(
    "post-User",
    "User",
    new { controller = "User", action = "create" },
    new { httpMethod = new HttpMethodConstraint("POST") }
    );

routes.MapRoute(
    "post-User",
    "{controller}",
    new { controller = "User", action = "create" },
    new { httpMethod = new HttpMethodConstraint("POST") }
    );

I thought that the {controller} bit was a placeholder and that saying controller = “User” in the next line would make these two statements equivilant. Apparently using {controller} sets up defaults for all routes?

  • 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-18T06:11:24+00:00Added an answer on June 18, 2026 at 6:11 am

    You are correct in your belief that the {controller} substring acts as a placeholder for a controller name. With that in mind, then, the following route will match any controller, but default to the User controller where no controller is specified:

    routes.MapRoute(
        "post-User",
        "{controller}",
        new { controller = "User", action = "create" },
        new { httpMethod = new HttpMethodConstraint("POST") }
    );
    

    The following, however, will match the route User and – because no controller can be specified – will always route to the User controller:

    routes.MapRoute(
        "post-User",
        "User",
        new { controller = "User", action = "create" },
        new { httpMethod = new HttpMethodConstraint("POST") }
    );
    

    In this instance the difference is meaningless because all you’re doing is forcing the route User to map to a controller User, which is exactly what will happen in your first route anyway.

    However, consider the following:

    routes.MapRoute(
        "post-User",
        "User/{action}",
        new { controller = "User", action = "MyDefaultAction" },
        new { httpMethod = new HttpMethodConstraint("POST") }
    );
    
    routes.MapRoute(
        "foo",
        "{controller}/{action}",
        new { controller = "User", action = "Index" },
        new { httpMethod = new HttpMethodConstraint("POST") }
    );
    

    Now, your top route will match requests to the User controller, with an optional action specified and will default to MyDefaultAction. Requests to any other controller will not match the first route – because the route does not begin with the constant string User – and will default back to the second route (foo). Again, the action is optional; however, now, unlike the requests to the User controller, your default action for other controllers will be the Index action.

    So now…

    .../User defaults to the MyDefaultAction action.

    .../SomeOtherController defaults to the Index action.

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

Sidebar

Related Questions

I recently got an email from a customer saying that they were getting errors
I recently got a new printer (specifically a HP Photosmart C6380 if that helps)
I recently got hired as a web developer, and the project that I am
We recently got a call from one of our clients, complaining that their site
I recently got informed that there is an OpenERP plugin for Eclipse IDE. Can
I recently got into closures and anonymous functions, and I'm wondering if my code
I recently got help on When select value from combo, highlight that record in
I recently got thinking about alignment... It's something that we don't ordinarily have to
I recently got the latest version of Hibernate and noticed that my UserTypes now
Just recently got into experimenting with NLog, and it occurs to me that I

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.