i have view (index.cshtml) grid (infragistics jquery grid) imagelink. if user clicks on link following jquery function called:
function confirmsettingenddateremarktoyesterday(remarkid) { //some code... //call action. $.post("home/setenddateremarktoyesterday", { remarkid: remarkid }, function (result) { //alert('succes: ' + remarkid); //window.location.reload(); //$('#remarksgrid').html(result); }); } commented out can see alert myself , 2 attempts refresh view. location.reload() works, work browser. .html(result) posts entire index.cshtml + layout.cshtml double in remarksgrid div. not correct.
this action calls (setenddateremarktoyesterday):
public actionresult setenddateremarktoyesterday(int remarkid) { //some logic persist change db. return redirecttoaction("index"); } this action redirects to:
[httpget] public actionresult index() { //some code retrieve updated remarks. //remarks pseudo list<of remark> return view(remarks); } if don't window.location.reload after succesfull ajax post view never reload. i'm new mvc, i'm sure there's better way this. i'm not understanding fundamental here. perhaps nudge in right direction? thank in advance.
as requesting ajax call, should redirect using response
modify controller return jsonresult landing url:
public actionresult setenddateremarktoyesterday(int remarkid) { //some logic persist change db. var redirecturl = new urlhelper(request.requestcontext).action("index", "controller"); return json(new { url = redirecturl }); } js call:
$.post("home/setenddateremarktoyesterday", { remarkid: remarkid }, function (result) { window.location.href = result.url });
Comments
Post a Comment