11

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.....

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. Commented Dec 8, 2013 at 6:22

1 Answer 1

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';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.