How to get current model in action filter

前端 未结 3 1392
粉色の甜心
粉色の甜心 2020-12-17 10:25

I have a generic action filter, and i want to get current model in the OnActionExecuting method. My current implementation is like below:

public         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 10:51

    You can use ActionExecutingContext.Controller property

        /// 
        /// Gets the controller instance containing the action.
        /// 
        public virtual object Controller { get; }
    

    and converting result to base MVC Controller get access to model:

    ((Controller)actionExecutingContext.Controller).ViewData.Model
    

提交回复
热议问题