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?
答案 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;
。