Getting controller name from razor

前端 未结 6 491
旧时难觅i
旧时难觅i 2020-12-03 13:11

I seem to be having a difficult getting something that should be easy. From within my view, using Razor, I\'d like to get the name of the current controller. For example, if

6条回答
  •  时光取名叫无心
    2020-12-03 14:02

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

    MVC 3

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

    MVC 4.5 Or MVC 5

    @ViewContext.RouteData.Values["controller"].ToString();
    

提交回复
热议问题