代码改变世界

[Tips]: ASP.NET MVC得到controller的名字

2009-07-08 14:01  敏捷的水  阅读(558)  评论(1编辑  收藏  举报

If you have the ControllerContext class instance available then you can use this code:

string controllerName= controllerContext.RouteData.GetRequiredString("controller");

the HTML helper provides access to the ControllerContext, you can use it in view page:

Html.ViewContext.Controller.ControllerContext.RouteData.GetRequiredString("controller")