asp.net mvc 4 - HttpPost action method recalled when the view presented by it is reloaded -
i have httppost action method receives model , saves database:
[httppost] public actionresult adddocument(document doc){ documentrepository repo= getdocumentrepository(); repo.savedocument(doc); return view(viewname: "docviewer", model: doc); }
so method receives model, saves , returns docviewer
view display added document. have 2 problems including 1 in question
- if press f5 after
docviewer
presented warning post method invoked again. how avoid this? i'm sure there's general practice - in
docviewer
view have defined html elements this:
<div>full name</div> <div>@html.labelfor(x=>x.fullname)</div> <div>address</div> <div>@html.labelfor(x=>x.address)</div> //and on
but following output:
full name fullname address address
shouldn't actual value not property name (or display name if it's provided)?
in post action not return model object view:
[httppost] public actionresult adddocument(document doc) { documentrepository repo= getdocumentrepository(); repo.savedocument(doc); //return view("docviewer"); tempdata["document"] = doc; return redirecttoaction("docviewer","controllername"); }
and in docviewer action:
public actionresult docviewer() { document doc = tempdata["docviewer"] document; return view(doc); }
updated:
you have redirect docviewer view via action avoid form post again if f5 pressed.
see details here
Comments
Post a Comment