I’m using the following route to handle localization on my ASP.NET MVC Application
routes.MapRoute("Globalization", "{culture}/{controller}/{action}/{id}",
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
So the scheme is http://mysite.com/en-US/Contact or http://mysite.com/es-ES/Contact
I’m trying to make some culture links in _Layout.cshtml in order to switch culture. But i need to only switch culture and stay on the same view.
Current View : http://mysite.com/en-US/Contact
=> Switch To es-ES
New View : http://mysite.com/es-ES/Contact
How can i perform that ?
Thanks.
This is quite tricky actually. You could simply use
@Html.ActionLink("Spanish", null, new { @culture = "es-ES" }), however this will preserve only parameters defined in route and query string will be lost in localized version. Because of this I’ve written following helper:With this
@Html.CurrentLink("Spanish", new { culture = "es-ES" })should accomplish exactly what you want.