asp.net mvc – Can the MVC ModelState span multiple controllers – Education Career Blog

I have an scenario where a view in controller A posts its form to an action in controller B, the data is then validated in that action, and if anything fails validation, errors are added to the ModelState, and then the action, redirects back to controller A so that the validation messages can be populated.

The problem I’m having is that, when I return back to controller A the view doesn’t seem to be picking up any of the validation errors. Does the ModelState only exist in the state of one controller?

,

Modelstate is essentialy viewdata, so it’s lifetime is for the request only. The work around you need is to store the modelstate in TempData. There’s a blog article about it here.

    using MvcContrib.Filters;

    ModelStateToTempData
    public class MyController : Controller {
      //
    ...
    }

Leave a Comment