从OnActionExecuting方法ASP.NET MVC 5访问自定义WebViewPage中的属性

时间:2016-10-05 13:32:28

标签: c# asp.net asp.net-mvc custom-action-filter

我有自定义WebViewPage,在这个类中,我有需要从ActionFilter初始化的属性。在这个过滤器中我有方法OnActionExecuting(ActionExecutingContext filterContext)。我可以从自定义WebViewPage访问属性吗?

CustomViewPage

public class BaseViewPage : WebViewPage
{
    public List<IAlert> Alerts { get; set; }
    public override void Execute() { throw new NotImplementedException(); }
}

ActionFilter

public class MessageFilter : IActionFilter
{
    public void OnActionExecuted(ActionExecutedContext filterContext) { }


    public void OnActionExecuting(ActionExecutingContext filterContext)
    {//I NEED ACCESS HERE TO ALERTS PROPERTY FROM BASEVIEWPAGE
    }
}

1 个答案:

答案 0 :(得分:0)

public void OnActionExecuting(ActionExecutingContext filterContext)
{ 
      //I NEED ACCESS HERE TO ALERTS PROPERTY FROM BASEVIEWPAGE

     BaseViewPage obj = new BaseViewPage();
     obj.Alerts // your logic
}