最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Get the MVC controller name in Javascript function - Stack Overflow

programmeradmin2浏览0评论

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.

For Example; function call from View:

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

Function parameters:

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

}

Thanks in advance.....

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.

For Example; function call from View:

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

Function parameters:

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

}

Thanks in advance.....

Share Improve this question edited Dec 8, 2013 at 6:02 amdixon 3,8338 gold badges26 silver badges35 bronze badges asked Dec 8, 2013 at 5:56 10K35H 5H4KY410K35H 5H4KY4 1,5265 gold badges21 silver badges43 bronze badges 1
  • The way I've been doing stuff like this is to put the partial url information in a data- attribute from the model when I build the view that I can read later using JQuery. – jfrankcarr Commented Dec 8, 2013 at 6:22
Add a comment  | 

1 Answer 1

Reset to default 22

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

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

Or

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

Update:

You can also get controller's name this way:

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

评论列表(0)

  1. 暂无评论