获得JavaScript函数MVC控制器名称 [英] Get the MVC controller name in Javascript function

查看:89
本文介绍了获得JavaScript函数MVC控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的 jQuery的的CRUD功能;这是从几个控制器的动作调用。
有什么办法找出哪些是位指示该有触发功能。

I have a Jquery CRUD function; which is called from several Controllers actions. Is there any way to find out which contoller is tiggering that function.

例如;从View函数调用:

For Example; function call from View:

$('a.Edit-Icon').live("click", function (event) { 
  editDialog(this, event, '#_List'); 
});

功能参数:

function editDialog(tag, event, target,value)
{
  ------
  // How to get the Controller name ???????????

}

在此先感谢.....

Thanks in advance.....

推荐答案

您可以得到控制的名字在JavaScript这种方式使用剃刀:

You can get controller's name in javascript this way using razor:

var controllerName = '@ViewContext.RouteData.Values["Controller"].ToString()';

或者

var controllerName='@HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString()';

更新

您还可以得到控制的名字是这样的:

You can also get controller's name this way:

var controllerName = '@ViewContext.Controller.ValueProvider.GetValue("controller").RawValue';

这篇关于获得JavaScript函数MVC控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆