Skip to content Skip to sidebar Skip to footer

Get The Mvc Controller Name In Javascript Function

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

Solution 1:

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';

Post a Comment for "Get The Mvc Controller Name In Javascript Function"