Given that web apps should always redirect after a POST (or any non-repeatable request to change server-side state) …
… how are people using MVC3 Model Validation and performing the mandatory redirect?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Usually you only redirect after a successful post (no Model Validation errors), otherwise you send back the page with a validation error message.
The redirect in the PRG pattern prevents double-posting, so there’s no harm to send back the same page (+ error message) because the post was not successful and will not be unless something changes to make validation pass.
Edit:
It looks like you’re looking for passing
ModelStateto the next (redirected) request. This can be done by usingTempDatato storeModelStateup to the next request. FYI,TempDatauses Session.This can be implemented with
ActionFilters. Examples can be found in the MvcContrib project code:ModelStateToTempDataAttributeThis has also been mentioned together with other tips in a ‘best practices’ article on weblogs.asp.net (seems the author has moved the blog, but I couldn’t find the article on the new blog). From the article:
Controller
Action Filters