0

I have MVC Routing issue in Sitecore. I have the following route in myRegisterRoutes() method. For this method I need to add language variant since I have enabled language fallback. Could some please help in this.

  1. For English: http://xyz.com/api/sitecore/Forms/SubmitForm
  2. For German: http://xyz.com/de-DE/api/sitecore/Forms/SubmitForm

Route map:

routes.MapRoute("FormsApi", "api/sitecore/Forms/SubmitForm",
    new { controller = "Forms", action = "SubmitForm" });
1

You could add your language as a parameter to the route. Something like this:

routes.MapRoute("FormsApiWithLanguage",
    "{languageCode}/api/sitecore/Forms/SubmitForm",
    new { controller = "Forms", action = "SubmitForm", languageCode = "en" }
    );

I'm just setting a default language code there with the "en" - now your language code would be passed into your action as a param:

public ActionResult SubmitForm(string languageCode) 
{
}

If that doesn't work, you could append the language code to the end of the route instead of the start.

| improve this answer | |
  • Thanks, this solution working fine when I am assigning in static value to languageCode. My requirement is to get Sitecore.Context.Language in RegiterRoute() method, but here I am not getting the Sitecore.Context.Language. So how can i get Sitecore.Context.Language in Routing? Thanks for help so far.. – Sai Charan Medavarapu Feb 10 '17 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.