Ajax controllers 404 when selecting multiple languages


Hello team,

My home page has couple of controller Action methods which are called through Jquery AJAX. These seem to work fine. As part of some research I enabled additional language in the CMS.

Now the action methods return 404 as it expects language indicator in the url (Ex: https://abc.com/en/ActionMethodName) .If I update the url in client side by adding this indicator then it works. I want to be able to update the url dynamically or at least default to /en version when nothing is passed from client side. If the AJAX url is https://abc.com/ActionMethodName I want it to redirect to english version. 

I tried to use the solution mentioned here  https://stefanolsen.com/posts/ensuring-the-right-ajax-content-language-using-a-filter-attribute/   but this still gives me 404. Any idea what I could be doing wrong here.

May 12, 2021 21:04
- May 13, 2021 11:32
Were you able to get the language code via the implementation (through the link you shared)? Or still the links are forming without language slug/code?

Hi Dileep

The solution in the linked blog post assumes that you call the action method using the default MVC URL format (/ControllerName/ActionName). This means you may need to add the default MVC route. Then you can provide the language code as a request header in the AJAX request.

If you want to keep the URL structure as it is, make sure you have specified a default language in the "Manage Websites" section. Make sure English is selected for the primary hostname of the website. Then English language will be used as default/fallback when your AJAX code does not include a language segment in the request URL.

May 13, 2021 17:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.