Answer the question
In order to leave comments, you need to log in
How to return Json files in MVC?
When changing the language on the site, the following request is sent
****/translate_(language).json
How can I intercept such requests and return json files?
After all, Url can be different (Home/translate_(language).json,
Home/screen/translate_(language).json).
the example was taken here
plnkr.co/edit/NX51vL4e7IEJqXjVe4nu
from the example you can see that the js code sends a request to the above link, maybe you can redirect the code to the controller I need which will return json files?)
I’m not friends with JS yet, but as they say ,really needed.
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
If you use the code from the example, then the URL to translate_(language).json files will be built relative to the current URL, as you wrote.
In order for the URL not to be built relative to the current address, you need to add '/' to 'translation_' (from the example). Then requests will go to a URL like http://run.plnkr.co/translation_(language).json and the example will not work.
In your case, the easiest option.
public class LanguageController : Controller
{
public ActionResult Index(string language)
{
[...]
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question