MVC View中获取action、controller、area名称
来源:互联网 发布:淘宝 亚瑟士 正品 编辑:程序博客网 时间:2024/06/16 05:59
获取控制器名称:
ViewContext.RouteData.Values["controller"].ToString();
获取Action名称:
ViewContext.RouteData.Values["action"].ToString();
获取路由参数值:
ViewContext.RouteData.Values[名称].ToString();
如:ViewContext.RouteData.Values["ID"].ToString(); 获取ID的值
获取area名称
在代码中:
ControllerContext.RouteData.DataTokens["area"]
在View中:
ViewContext.RouteData.DataTokens["area"]
获取 ViewName:
public static string CurrentViewName(IView view) { if (view is BuildManagerCompiledView) { string viewName = ((BuildManagerCompiledView)view).ViewPath; viewName = viewName.Substring(viewName.LastIndexOf('/')); viewName = Path.GetFileNameWithoutExtension(viewName); return viewName; } return string.Empty; }
具体代码
var action = ViewContext.RouteData.Values["Action"].ToString().ToLower();var controllerName = ViewContext.RouteData.Values["controller"].ToString().ToLower();var areaName = ViewContext.RouteData.DataTokens["area"].ToString().ToLower();
0 0
- MVC View中获取action、controller、area名称
- MVC View中获取action、controller、area名称
- MVC View中获取action、controller、area名称、参数
- MVC中获取当前URL、controller、action
- MVC中如何获取当前action、controller
- 获取当前URL、area、controller、action
- .net mvc 获取url中controller和action
- 在ASP.NET MVC 中获取当前URL、controller、action
- .net mvc 获取url中controller和action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- ASP.NET MVC 中 当前controller、action的获取
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- .net mvc 获取url中controller和action
- Shiro & CAS 实现单点登录
- CentOS7安装Proftpd
- Volley框架的基本解读(七)
- docker 命令
- 发现和记录--Nginx配置文件详细说明--负载均衡
- MVC View中获取action、controller、area名称
- sql anywhere11 mobilink11通信
- shell获取系统时间
- Centos 6.5 Nginx 安装-配置-实战
- chrome调试手机解决跨域
- Android 如何根据比例绘制一个不同颜色的圆
- sql语句中----删除表数据drop、truncate和delete的用法
- Android Studio SDK目录结构
- Elasticsearch NoNodeAvailableException 问题解决