Exporting ViewData\ModelState to Child Action
As the subject says, is this a bad idea? If so, why?
Cu开发者_开发问答rrently, if you are rendering some input fields from inside a @Html.Acion, the validation errors don't get displayed to the user as the ModelState gets cleared when the @Html.Action gets involved (in its context.)
So whats the best pattern around it?
You can access the parent contexts via ControllerContext.ParentActionViewContext
or ViewContext.ParentActionViewContext
(details here) but I think there are better solutions.
A child action is a good choice when you do not want to pollute all of your view models with data which are available independent from the current controller action and view (for example a user welcome label, a navigation bar, etc.).
For other reuse scenarios like common input fields a partial view is a better approach.
However if you give more details about your current scenario I try to suggest a more specific solution.
精彩评论