ASP MVC 2 Change language by url
I'm trying to create a languageswitch for a website with 2 or more languages.
When I follow the default route (controller/action) the Html.ActionLink("NL", ViewContext.RouteData.Values["action"].ToString(), new { language = "nl-NL" }, null)
does it's work. But when called from an Action with parameters, it (logically) only cre开发者_如何学编程ates a link to the Controller with the current Action. The parameters are ignored.
My current route:
routes.MapRoute(
"ProjectCategory",
"{language}/Projects/{action}/{slug}",
new { controller = "Projects", action = "Detail", slug = string.Empty, language = "en-US" }
);
The link created with Html.ActionLink
:
http://localhost/mysite/nl-NL/Projects/Detail/
How to solve this problem?
HttpContext.Current.Request.Path.Replace("/en-US/", "/nl-NL/")
It's not the most elegant way, but works for me. (Of course you should replace en-US
with the current lang)
精彩评论