The problem: How to update ModelState in posting+validation scenario.
I\'ve got a simple form:
<%= Html.ValidationSummary() %>
<% using(Html
am I doing something extremely uncommon or am I missing something?
I think this is pretty rare. I think MVC is assuming validation errors are a yes/no affair, and in this case you're using a validation error as a means to give general user feedback.
I think MVC also seems happiest when POSTs either fail due to validation errors, or perform an action and redirect or render something completely different. Outside for model validation errors, it's pretty rare to re-render the same input.
I've been using MVC for about a year now and just ran into this in another context, where after a POST I wanted to render a fresh form as the response.
[HttpPost]
public ActionResult Upload(DocumentView data) {
if(!ModelState.IsValid) return View(data);
ProcessUpload(data);
return View(new DocumentView());
}
MVC is rendering the ModelState from data, not my new object. Very surprising.
If the former, then how could I implement such functionality in a better way