My first ASP.NET MVC 6 / jQuery web site - the site header has a "Change Language" selector (named LanguagePicker
) - this is actually placed in a _Layout view, a container shared by all views.
When users change the language, I need to save that in the db, and reload current page, with language changed.
I have this on client-side:
$('#LanguagePicker').selectpicker('val', '@CultureHelper.GetCurrentLanguage()');
$('#LanguagePicker').on('change', function () {
var currentPageUrl = 'TODO'; // Get current Url here
window.location = "/Base/ChangeLanguage/" +
$('.selectpicker option:selected').val() +
"?returnUrl=" + currentPageUrl ;
});
});
Is there a better way to do this, both in client side code and in server side? Ideally, the purpose is to send a newLanguage
param to the server, save to db, and then refresh the current page so that the resources associated with the new language are displayed. it should obviously work from whatever page it is triggered.