Get triggered filter MVC Controller, Action, parameters, etc.

The first is to implement the interface System.Web.Mvc.IActionFilter filter

Get Controller, Action, parameters

method one,

string actionName = filterContext.ActionDescriptor.ActionName;
string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
//获取触发当前方法的Action方法的所有参数
//(因为参数可能有多个,所以它是一个集合,它的返回值类型是IDictionary<string ,object>)
var paramss = filterContext.ActionParameters;

Method Two,

var routeData = filterContext.RouteData;
string actionName = routeData.Values["Controller"].ToString();
string controllerName = routeData.Values["Action"].ToString();
var param = routeData.Values["Id"];

Source: https://www.bbsmax.com/A/6pdDP1gkdw/

Guess you like

Origin www.cnblogs.com/jsll/p/11746383.html