考虑以下情况。在我的控制器中,我有:
public ActionResult Edit(int id)
{
...
}
[HttpPost]
public ActionResult Edit(Model model)
{
...
}
我还有一个ActionFilterAttribute
,它适用于同一控制器的其他一些操作。在OnActionExecuting
我需要获取操作的方法ActionDescriptor
中HttpGet
Edit
:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// as this is called from the same controller, I use
ActionDescriptor action = filterContext.ActionDescriptor.ControllerDescriptor
.FindAction(filterContext.Controller.ControllerContext, "Edit");
...
}
问题是,该方法在请求的情况下FindAction
返回对操作的“引用” 。我如何让它只寻找动作?HttpPost
Edit
POST
HttpGet