Exporting ViewData\ModelState to Child Action

前端 未结 1 1459
庸人自扰
庸人自扰 2021-01-19 08:11

As the subject says, is this a bad idea? If so, why?

Currently, if you are rendering some input fields from inside a @Html.Acion, the validation errors don\'t get di

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-19 08:41

    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.

    0 讨论(0)
提交回复
热议问题