In ASP. net mvc, URLRouting is also a URL routing. This is a magic function that can convert a Url into a Url that meets user habits or is more friendly to search engines. Simply post the Code:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
This is the default MVC route. now, I want to implement a URL like this: The http://www.abc.com/apple/ makes its corresponding controller Home and action google. the simple content is not much said. Simply paste the Code:
routes.MapRoute(
"Topic", // Route name
"apple", // URL with parameters
new { controller = "Home", action = "google" }// Parameter defaults
);
Now there is an Actionlink: @ Html. actionLink ("Apple", null, "apple", null, new {@ class = "abc"}), this ActionLink is in a _ Layout. cshtml, when we request this ActionLink for the first time, it will be correctly resolved to the Home controller, google Action, the address is displayed as a http://www.abc.com/apple/ after the jump, the second request for this ActionLink, the parsing is still Home controller, google Action, but the Url in the address bar will become the http://www.abc.com/Home/google if you change the null in the action to a null character will not this situation. but it is really a little painful. Why is the address bar wrong only after one jump?
Thank you for reminding me on the first floor. I reversed the action and controller above, Khan. I am very sorry. It has been modified.
In addition, the focus of my talk is to turn the Url into a http://www.abc.com/apple/. This article also means that when you set the action in Actionlink to null, (For the moment, the first digit of the Url root directory is called the second digit of controller.) If the action in the current Url is the default action of route (such as Index), the returned action is null. if not, the action in the Url will be the current action in the route. in this case, your original url is changed. if you set the action item to a null character, the Url after the jump will always be http://www.abc.com/apple/and it will become http://www.abc.com/home/google.