All viewmodels inherit from 'BaseViewModel', can I set this up in OnActionExecuting?

后端 未结 1 1820
星月不相逢
星月不相逢 2021-01-23 14:42

If all my actions have a model that inherits from BaseViewModel, is it possible to initialize this model from the OnActionExecuting method?

Currently in all my actions I

1条回答
  •  抹茶落季
    2021-01-23 15:26

    You can't do it in OnActionExecuting, since at that point you don't know which subclass of BaseViewModel to use. However, you can update the model in OnActionExecuted, which runs after the action method but before the view is rendered.

    Most likely you are populating these properties to use in the view only, but if you do need access to them in the action method you can put them into ViewBag or a controller property in OnActionExecuting and add them to the model in OnActionExecuted

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