0

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 creates 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?

MysticEarth
  • 2,646
  • 4
  • 33
  • 53

1 Answers1

1
 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)

Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206