Get current controller in view

后端 未结 7 867
北荒
北荒 2020-12-04 11:55

I have a View - _Edit which lives in News M/V/C.

I reuse the V/M via the CategoryController as:

r         


        
7条回答
  •  借酒劲吻你
    2020-12-04 12:37

    You can use any of the below code to get the controller name

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

    If you are using MVC 3 you can use

    @ViewContext.Controller.ValueProvider.GetValue("controller").RawValue
    

提交回复
热议问题