How to return model state from child action handler in ASP.NET MVC
- by Joe Future
In my blog engine, I have one controller action that displays blog content, and in that view, I call Html.RenderAction(...) to render the "CreateComment" form. When a user posts a comment, the post is handled by the comment controller (not the blog controller).
If the comment data is valid, I simply return a Redirect back to the blog page's URL.
If the comment data is invalid (e.g. comment body is empty), I want to return the ViewData with the error information back to the blog controller and through the blog view to the CreateComment action/view so I can display which fields are bad.
I have this working fine via AJAX when Javascript is enabled, but now I'm working on the case where Javascript might be disabled.
If I return a RedirecToAction or Redirect from the comment controller, the model state information is lost.
Any ideas?