How to show route default value?
I have a route:
"{culture}/{controller}/{action}/{id}",
new { culture = "en", controller = "Home", action = "Index", id = UrlParameter.Optional }
The Url becomes
h开发者_开发知识库ttp://mysite.com
I want to show the culture name so that the url will look like this:
http://mysite.com/en
Defaults are always hidden
Defaults are always hidden as long as all values after it are provided with defaults as well. You will have to provide two route definitions:
"en/{controller}/{action}/{id}", new { culture = "en" , ... }
"{culture}/{controller}/{action}/{id}", ...
The first one will always add en
after domain address for outbound links and will also process the request when an inbound request will start with en
segment.
In case culture is different than English, second route will get hit and process inbound and outbound routing.
Note about [in/out]bound:
- Inbound routing processes requests when they hit your server
- Outbound routing processes when you generate URLs on your views (links, form actions...)
精彩评论