Get the MVC controller name in Javascript function

后端 未结 1 1856
青春惊慌失措
青春惊慌失措 2021-01-17 17:20

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.

Fo

相关标签:
1条回答
  • 2021-01-17 18:11

    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 讨论(0)
提交回复
热议问题