Filp route value in asp.net mvc routes
- by Herman
Hi all,
I am new to asp.net mvc, so please bear with me.
We have the following route dictionary setup.
routes.MapRoute(
"Default", // Route name
"{language}/{controller}/{action}/{id}", // URL with parameters
new { language = "en", controller = "Home", action = "Index", id = "" } // Parameter defaults
);
for any given page in our app, we to render a link to the a french version of the same page. For example, the page:
http://www.example.com/en/home
should have link on that page that points to
http://www.example.com/fr/home
Now I have the following UrlHelper extension method
public static string FilpLanguage(this UrlHelper urlHelper)
{
var data = urlHelper.RequestContext.RouteData;
if (System.Threading.Thread.CurrentThread.CurrentCulture == CultureInfo.GetCultureInfoByIetfLanguageTag("en-CA"))
data.Values["language"] = "fr";
else
data.Values["language"] = "en";
return urlHelper.RouteUrl(data.Values.Where(item => item.Value != null));
}
However, calling FilpLanguage on www.example.com/en/home will return the following URL:
www.example.com/en/home?current=[,]
Am I missing something here? where did the current parameter come from?
Thanks in advance.