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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:11:59+00:00 2026-06-02T22:11:59+00:00

I am learning MVC routing. Hope my question doesn’t look silly, and please help

  • 0

I am learning MVC routing. Hope my question doesn’t look silly, and please help 🙂

public static void RegisterRoutes(RouteCollection routes) {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );

Msdn reference says it takes a String, String, Object, so I try to make a small change (added a “my” in front of everything just to mod the names and see if it works):

    public static void RegisterRoutes(RouteCollection routes) {
        routes.IgnoreRoute("{myresource}.axd/{*mypathInfo}");

        routes.MapRoute(
            "myDefault", // Route name
            "{mycontroller}/{myaction}/{myid}", // URL with parameters
            new { mycontroller = "Home", myaction = "Index", myid = UrlParameter.Optional } // Parameter defaults
        );

It doesn’t work any more. What is the format of these strings in “{}” curly brackets, and the anonymous object value formats.

{controller}/{action}/{id}
/Products/show/beverages

{table}/Details.aspx
/Products/Details.aspx

blog/{action}/{entry}
/blog/show/123

{reporttype}/{year}/{month}/{day}
/sales/2008/1/5

{locale}/{action}
/US/show

{language}-{country}/{action}
/en-US/show

{controller}/{action}/{id}
http://server/application/Products/show/beverages

{resource}.axd/{*pathInfo}
http://server/application/WebResource.axd?d=…

I google’d around, but all the posts seem to assume I know the formats, and couldn’t find any detail explanation.Do they have to be fixed names like {controller} {action} {id} etc, or they won’t work? Does the default anonymous object value names need to match them, too? Further, what does the “*” mean in {*pathInfo} I couldn’t find the explanation for that, neihter. Thank you.

  • 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-02T22:12:02+00:00Added an answer on June 2, 2026 at 10:12 pm

    First, we need some definitions here.

    Let’s break down the default route.

    routes.MapRoute( 
        "Default", // Route name 
        "{controller}/{action}/{id}", // URL with parameters 
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
    ); 
    

    In this case, Default, on line 2, is merely a text name used to identify the route.

    On line 3 is the url pattern. This defines how the route is matched. the things in braces are placeholders. They map to parameter names. so {controller} maps to the controller name. {action} maps to action name, and {id} maps to parameter called id.

    On line 4 is the defaults object. This object supplies default values when they cannot be inferred from the url.

    So, if we take all that together, here are some conclusions we can draw:

    the default objects only supply values when they cannot be inferred from the url string. Thus, when the incoming request is just /, the dfault values from line 4 are used for controller and action. If the incoming request is /Blah, then the default controller supplied on line 4 is ignored, and instead MVC looks for BlahController. However, since no action was specified, the default action from line 4 is used Index.

    The key thing to remember here is that the values on line 4 are only used if nothing matches the url in line 3.

    So, when you changed everything, you threw everything for a loop. It’s a meaningless route, because nothing defines which controller or action to use, and those two values are required in order to complete the route. As such, MVC can’t figure out what controller you want. Or action method for that matter.

    Another example:

    routes.MapRoute(
        "Example",
        "Home/{action}/{myid}",
        new { controller = "NotHome", action = "Index", myid = UrlParameter.Optional }
    );
    

    Because there is no {controller} placeholder in the url, then the default of “NotHome” is used, which makes MVC look for NotHomeController. So a url of /Home/About/3 would mean that controller = “NotHome”, action = “About”, and myid = 3.

    All in all, in an incoming route, something must fill in the value for controller and action at a minimum. id is optional, and can be renamed to whatever you like. But, something must set controller and action parameters or MVC doesn’t know how to route things.

    Also, remember, the default route (or an effective default route) must come last in the list, otherwise no other routes will be matched.

    The {*pathInfo} bit is called a slug. it’s basically a wildcard saying “everything after this point is stuffed into a parameter called pathInfo”. Thus if you have "{resource}.axd/{*pathInfo}" and a url like this: http://blah/foo.axd/foo/bar/baz/bing then two parameters get created, one called resource, which would contain foo and one called pathInfo which contains foo/bar/baz/bing.

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

Sidebar

Related Questions

Can someone please explain what the following function does. I am learning Asp.net MVC
I am learning MVC with Razor and have a simple question (I think). I
(just learning MVC) I have created a model class: public class Employee { public
I am learning MVC and I need to understand why it doesn't work the
I'm just learning MVC and want to add some custom routing to my site.
I'm just learning MVC and have a question that I'm sure is obvious to
I am learning MVC and new to it. I have read some articles on
I'm learning MVC and am having trouble deciding when I should create a new
I am learning MVC from Stephen Walther tutorials on MSDN website. He suggests that
Just I am learning MVC,(ofcourse i get enough information from MS Website).I want to

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.