When you create a new MVC project and run it directly, you will see the welcome homepage. But when you go to the project, you will find that there is no corresponding page in the project?
That is, MVC Routing is working. Open Global. asax and you can see the corresponding Routing code.
Code Public static void RegisterRoutes (RouteCollection routes)
{
Routes. IgnoreRoute ("{resource}. axd/{* pathInfo }");
Routes. MapRoute (
"Default", // custom name
"{Controller}/{action}/{id}", // Parameter
New {controller = "Home", action = "Index", id = UrlParameter. Optional} // default value of the Parameter
);
}
After the program runs, it will take the default value, go to the address http: // localhost: 1234/Home/Index.
There is an agreement that everyone should follow.
Home indicates that the address is protected against the Controller file HomeController. cs;
Index indicates the Index method in the HomeController. cs file to be executed.
Custom rules:
Routes. MapRoute (
"Shop ",
"Shop/{action}/{year }",
New {controller = "shoping", action = "Index", year = 2000 },
New {year = "\ d {4}"}); // you can use a regular expression to restrict the year.