I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same link just change de to en. If I am trying to get values with ViewContext.RouteData.Values[“id”]; I getting null value. Any ideas?
@Html.ActionLink("New Language",
ViewContext.RouteData.GetRequiredString("action"),
ViewContext.RouteData.GetRequiredString("controller"),
new { lang = "en" }
)
You could write a custom url helper:
and then use it like this in the view:
and you could of course write another helper to make the rendering of the entire anchor which would use our first helper:
and then:
Now if we suppose that you navigated to
/de/home/index/123?param1=value1¶m2=value2, then the@Html.ChangeLanguage("en", "~/content/flag_en.jpg")would have generated the following markup: