ASP. net mvc routing rules

Source: Internet
Author: User

When reading a book, I like to think about it. I like to ask myself why, but I am stupid and cannot find the answer for a long time. How can this be better? God, give me a smart brain! Or tell me how to solve problems quickly. This blog is nothing more than a solution to the problem.ProgramPersonnel, although I cannot calculate it, the source code may be the essence of the problem.

When you create an ASP. NET. MVC project, a default routing rule is displayed, in the following format:

 
Routes. maproute ("default", // route name "{controller}/{action}/{ID}", // URL with parameters new {controller = "home ", action = "Index", id = urlparameter. optional} // default value );

We know the placeholder in the braces. Since it is a placeholder, can it be changed to another one?

Routes. maproute ("Default",//Route name"{Action}/{ID}",//URL with ParametersNew{Controller ="Home", Action ="Logon", Id = urlparameter. optional}//Default Value);

 

This is acceptable, but it cannot be changed to the following, and the result is incorrect.

 
Routes. maproute ("Default",//Route name"{Action}/{ID}",//URL with ParametersNew{Action ="Logon", Id = urlparameter. optional}//Default Value);

 

The error message also prompts that "controller" is required. For my first case, that is, although the following rule does not appear, it does appear in the default value, that is to say, there is still a "controller"

 
Routes. maproute ("default", // route name "{action}/{ID}", // URL with parameters new {controller = "home", Action = "Logon ", id = urlparameter. optional} // default value );

 

I decided to find the answer, so I decompiled it.CodeYou can see the answer you want:

 

 

Similarly, action must also appear.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.