如何在IActionFilter MVC6中设置ViewBag?

时间:2016-07-18 06:19:45

标签: override viewbag

public class MAttribute : IActionFilter
{

public void OnActionExecuted(ActionExecutedContext actionContext)
    {
        string searchData = "";
        actionContext.Controller.ViewBag.SearchItem = searchData;
        //object not included in the definition
    }

}

当我覆盖IActionFilter时,它会提示'对象未包含在定义中,那么如何在IActionFilter MVC6中设置ViewBag?

1 个答案:

答案 0 :(得分:0)

尝试从ActionFilterAttribute继承 我认为您想要的方法签名是OnActionExecuting(ActionExecutingContext)

有关详细信息,请参阅:http://www.strathweb.com/2015/06/action-filters-service-filters-type-filters-asp-net-5-mvc-6/

编辑:如果您还没有,您可能还想在顶部添加using Microsoft.AspNetCore.Mvc.Filters;