asp.net mvc - jQuery Reload current page after return from MVC Controller Action called from jQuery -
asp.net mvc - jQuery Reload current page after return from MVC Controller Action called from jQuery -
i have code in global.asax need executed after jquery phone call controller action performs logic. need reload current page (whatever page is) after controller action returns.
jquery phone call controller action
<script type="text/javascript"> $(function () { $('#selectedlanguage').on('change', function () { var civilization = $(this).val(); $('#test').load("/account/testpartial/" + culture); //location.reload(true); homecoming false; }); }); </script> controller action /account/testpartial
[allowanonymous] public actionresult testpartial(string id) { setlanguage(id); var model = new languagelistpartialviewmodel(); model.languages = getlanguagelist(); model.selectedlanguage = id; homecoming view(model); } i tried location.reload(true); reloads immediately. need wait until controller action returns. tried implement await in controller action, guess i'm not sure how code since none of called routines within of testpartial homecoming compatible await.
jquery .get() seems option? these mean have convert jquery calling parameter json , code controller action json, or there way create phone call as-is using .get()?
if you're going reload page after bit of ajax returns, there's no point in using ajax. normal or post.
that said, problem here ajax asynchronous. in other words, after line $('#test').load(...) executed, next line executed, before whole ajax bit has had chance send request , receive response. in order execute code after response has returned, have pass callback:
$('#test').load('/account/testpartial/' + culture, function () { // }); jquery asp.net-mvc asp.net-mvc-4
Comments
Post a Comment