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

  1. if press f5 after docviewer presented warning post method invoked again. how avoid this? i'm sure there's general practice
  2. 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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -