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?

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.