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?
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?
What you mean by the "mandatory" redirect? Often we use a try/catch in controller, if try is successful, you can either redirect to a View(if you NEED to) or can also return any partial view, or anything you need. The catch is often redisplaying the original page with error message since the post request is not success.
Hope I did not misunderstand you :)
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
ModelState
to the next (redirected) request. This can be done by usingTempData
to storeModelState
up to the next request. FYI,TempData
uses Session.This can be implemented with
ActionFilters
. Examples can be found in the MvcContrib project code:ModelStateToTempDataAttribute
This 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