[Tips]: ASP.NET MVCはコントロールの名前を得た

571 ワード

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")