1.视图中获取:
var actionName=ViewContext.RouteData.Values["action"].ToString().ToLower();
var controllerName = ViewContext.RouteData.Values["controller"].ToString().ToLower();
2.过滤器中获取
var controllerName = (filterContext.RouteData.Values["controller"]).ToString().ToLower();
var actionName = (filterContext.RouteData.Values["action"]).ToString().ToLower();
3.Action中
string controllerName = this.GetType().Name;
string controllerName = ControllerContext.RouteData.GetRequiredString("Controller");//小写不带Controller
string actionName = ControllerContext.RouteData.GetRequiredString("Action");//demo
MVC 获取controllerName和actionName
最新推荐文章于 2023-12-07 17:10:52 发布