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.