ASP.Net MVC2 -- After posting, how to clear form if user hits Back button? -


in web app, after clicking submit button on asp.net mvc form, user displayed either error screen or success screen. in case of error, user instructed click button on browser , fix whatever didn't right , try submitting again.

this works fine because when user clicks back, entered data still in screen in various fields. in case of success screen, data cleared if user clicks back, cannot accidentally re-submit data again.

how 1 in asp.net mvc?

the way can accomplish use post-get-redirect pattern. it's not asp-mvc specific wiki says

a common design pattern web developers avoid duplicate form submissions , allow user agents behave more intuitively bookmarks , refresh button.

clicking not safe way handle this. browsers don't maintain form state after submission. pattern directly address accidentally re-submit data issue.

in terms of code, have @ blog post jag reehal concerning how unit test controllers.

[httppost] public actionresult create(someviewmodel model) {   if (modelstate.isvalid)   {      // stuff saves data , then...      return redirecttoaction("success");   }   else   {      // model not valid return form user       // additional modifications.      return view(model);   }    } 

note: while above uses modelstate data validation, may have own set of validations , error checking routines can used in pattern.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -