Filp route value in asp.net mvc routes

Posted by Herman on Stack Overflow See other posts from Stack Overflow or by Herman
Published on 2010-04-05T16:41:00Z Indexed on 2010/04/05 16:43 UTC
Read the original article Hit count: 246

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc