c# - WebGrid in Razor View not updated/refreshed after RedirectToAction after POST -
have similar problem post...
webgrid not refreshing after delete mvc
whatever try, webgrid doesn't updated/refreshed after inline editing/deletion although viewmodel contains correct data before view shown...
inside controller:
public actionresult addtermin(int? id, int? ser) { ... viewmodel = ... //contains correct (=updated) data return view(viewmodel); //contains correct (=updated) data }
inside view "addtermin.cshtml":
@{ var data = new list<appointment>(); if (model != null && model.recurringappointments != null) { data = model.recurringappointments.appointments; //contains correct (=updated) data } var grid = new webgrid(source: data, rowsperpage: 10); //contains correct (=updated) data } ... @grid.gethtml(...) //shows wrong (=old/previous/cached) data - ???
i had added following entry in web.config already...
<system.web> <caching> <outputcache enableoutputcache="false" /> </caching> </system.web>
i tried "[outputcache(duration = 0)]" already.
and tried "jquery.ajaxsetup({ cache: false });".
and tried "modelstate.clear();" already. nothing works.
how can webgrid show updated data? have idea?
many in advance!
i solve problem now, should mention i'm using ajax post. since action in controller called ajax post , since there successfull redirect addtermin action via redirecttoaction then, didn't want believe ajax post might reason why webgrid isn't updated. reason. solution helped me: view not refreshing after ajax post
my solution looks now... instead of "redirecttoaction", use now:
[httppost] public actionresult updateappointment(appointment appointment) { ... //old: //return redirecttoaction("addtermin"); //new: var redirecturl = new urlhelper(request.requestcontext).action("addtermin", "veranstaltung"); return json(new { url = redirecturl }); }
and in view "addtermin.cshtml":
$(function () { $('.saveapp').on('click', function () { ... var appointment = { ... }; $.ajax({ url: '/veranstaltung/updateappointment', data: json.stringify(appointment), type: 'post', contenttype: 'application/json; charset=utf-8', success: function (result) { window.location.href = result.url; }, error: function (errorthrown) { ... } }); }); })
it works fine me.
Comments
Post a Comment