How to return model state from child action handler in ASP.NET MVC

Posted by Joe Future on Stack Overflow See other posts from Stack Overflow or by Joe Future
Published on 2010-06-03T17:51:35Z Indexed on 2010/06/03 17:54 UTC
Read the original article Hit count: 601

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about validation