MVC View中获取action、controller、area名称、参数

获取控制器名称:

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"]

 

具体代码

var action = ViewContext.RouteData.Values["Action"].ToString().ToLower();var controllerName = ViewContext.RouteData.Values["controller"].ToString().ToLower();
var areaName = ViewContext.RouteData.DataTokens["area"].ToString().ToLower();var modalID = Request["ModalID"];//举例,url如 edit?modalid=1

 

 

时间: 2024-09-20 05:35:13

MVC View中获取action、controller、area名称、参数的相关文章

ASP.NET在MVC控制器中获取Form表单值的方法_实用技巧

本文实例讲述了ASP.NET在MVC控制器中获取Form表单值的方法.分享给大家供大家参考,具体如下: 在MVC控制器中,如果我们想直接获取表单中某个标签元素的值,可以使用MVC中提供的FormCollection类,具体用法如下所示: 视图部分: @using (Html.BeginForm()) { <text>您输入的值是:</text><span>@ViewBag.FormValue</span> <input type="text&

eclipse rcp 代码中获取action对象

问题描述 eclipse rcp 代码中获取action对象 请问有没有什么办法可以在Activator中获取extensions中添加的工具栏或者菜单栏按钮对象,这样可以在代码中控制每一个action对应图标的样式,以及各action的可用和不可用状态.

struts2 怎么在js中获取action传回的数据

问题描述 struts2 怎么在js中获取action传回的数据 在action类里 有一个 List users = new ArrayList();action返回之后想要想要在onload里 先把users做一下处理这时在function load(){ .... }中怎么得到users 解决方案 可以用EL表达式var t = ${users} 解决方案二: 在js里可以直接用var t = '' 关键不要忘了最外面的引号 if和iterator可以直接用 不需要引号 解决方案三: 如果

android-从 OnCheckedChangeListener 的 CompoundButton中获取CheckBox key的名称

问题描述 从 OnCheckedChangeListener 的 CompoundButton中获取CheckBox key的名称 我使用接口 OnCheckedChangeListener,当点击 checbox 时 onCheckedChanged 方法被摧毁. 程序中有 10 个checkboxes.如何获取 CompoundButton 中点击的checkbox的名称?我觉得 CompoundButton 有所有需要的值,但是不知道怎么获取这个值. 例如: <CheckBox andro

YII MVC View中的$this

WebsiteController Java代码   <?php   class WebsiteController extends CController   {       function actionIndex()       {           $this->pageTitle = 'Controller context test';           $this->render('index');       }       function hello()      

mvc view 中如何在页面填入的值传到同一个页面的链接参数

问题描述 <legend>单据信息</legend><dl><dt>客户:</dt><dd><inputtype="hidden"name="tranorderSelect.cid"/><inputclass="required"name="tranorderSelect.cName"type="text"readon

MVC模式中在Action中model总是私自动设为finaL

问题描述 privatefinalCreateProjectPlanshModelmodel=newCreateProjectPlanshModel();想去又去不掉,什么情况? 解决方案 解决方案二:你用的是struts2还是Spring的MVC?不太明白解决方案三:Spring的,final去掉后保存又自动生成

asp中获取当前页面的地址与参数的函数代码_应用技巧

复制代码 代码如下: Function getCurrentUrl() On Error Resume Next Dim strTemp If LCase(Request.ServerVariables("HTTPS")) = "off" Then strTemp = "http://" Else strTemp = "https://" End If strTemp = strTemp & Request.Serve

asp中获取当前页面的地址与参数的函数代码

复制代码 代码如下: Function getCurrentUrl() On Error Resume Next Dim strTemp If LCase(Request.ServerVariables("HTTPS")) = "off" Then strTemp = "http://" Else strTemp = "https://" End If strTemp = strTemp & Request.Serve