如果在action方法中有一个model-bound参数,那么你如何在action过滤器中得到该参数呢?
[MyActionFilter] public ActionResult Edit(Car myCar) { ... } public class MyActionFilterAttribute : ActionFilterAttribute { public void OnActionExecuted(ActionExecutedContext filterContext) { //I want to access myCar here } }
有没有通过Form变量获取myCar?
解决方法
不确定OnActionExecuted,但可以在OnActionExecuting中执行:
public class MyActionFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { // I want to access myCar here if(filterContext.ActionParameters.ContainsKey("myCar")) { var myCar = filterContext.ActionParameters["myCar"] as Car; if(myCar != null) { // You can access myCar here } } } }