asp.net mvc - Browser back button and duplicate data entry -
i follow prg pattern avoid form resubmission problem when page refreshed. these action metods:
public viewresult adddcoument(){ ..... return view(); } [httppost] public redirecttorouteresult savedocument(document doc){ //save document return redirecttoaction("viewdocument",new { docid =doc.docid}); } public viewresult viewdocument(string docid){ document doc=getdocumentbyid(docid); return view(doc); }
when hit submit button document saved , redirected viewdocument action , helps prevent form resubmission when page refreshed. there's problem, problem can still click browser button, take me data entry form entered data remaining , can click submit again, means duplicate entry. 1 might need have unique entry not let duplicate saved server. in fact have , documentid, it's assigned automatically, not user input. how handle case?
update: actualy found way around issue. per this blog , many other threads need supply following http header in order turn off browser caching:
cache-control: no-cache, max-age=0, must-revalidate, no-store
i've tried both following ways:
the encapsulated, oop way:
var cache=response.cache; cache.setexpires(datetime.utcnow.adddays(-1)); cache.setvaliduntilexpires(false); cache.setrevalidation(httpcacherevalidation.allcaches); cache.setcacheability(httpcacheability.nocache); cache.setnostore();
and appending header string:
response.appendheader("cache-control", "no-cache, max-age=0, must-revalidate, no-store");
i tried adding them both method renders form , post method submits form. still form inputs repopulated cache.
Comments
Post a Comment