I am trying to implement a language chooser which is visible on all pages.
My application currently has two routes:
routes.MapRoute(
name: "EventDriven",
url: "{language}/{eventid}/{controller}/{action}/{id}",
defaults: new { language = "en", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{language}/{controller}/{action}/{id}",
defaults: new { language = "en", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
And in my shared _layout.cshtml
file I have the following action links:
@Html.ActionLink("English", ViewContext.RouteData.Values["action"].ToString(), new {language="en"})
@Html.ActionLink("Français", ViewContext.RouteData.Values["action"].ToString(), new {language="fr"})
The problem I am encountering is I want the {eventid}
route segment preserved, but it's not applicable on every url.
On the home index page http://localhost/MySite/
, the two action links are as follows:
English: http://localhost/MySite/
French: http://localhost/MySite/fr
Which is good, but on my interior page http://localhost/MySite/en/2/Donation
the action links are:
English: http://localhost/MySite/en/2/Donation
French: http://localhost/MySite/fr/Donation
If I go to http://localhost/MySite/fr/2/Donation
then the action links are:
English: http://localhost/MySite/en/Donation
French: http://localhost/MySite/fr/2/Donation
The problem is the change language action link does not contain the eventid 2
information.
How do I make it so both links contain the event and language information (and any other route parameters unforeseeable in the future) without having to program explicitly for them?