c# – AspNetCore.Mvc中的descriptor.ControllerDescriptor.Cont
发布时间:2020-12-15 23:40:31 所属栏目:百科 来源:网络整理
导读:我正在构建一个ASP.NET Core 2.0 Web应用程序.在ASP.NET WEB中我使用了System.Web.Mvc,其中我有以下行来获取ControllerName: descriptor.ControllerDescriptor.ControllerName 在ASP.NET Core 2.0中,这不起作用我收到错误: Error CS1061 ‘ActionDescripto
我正在构建一个ASP.NET Core 2.0 Web应用程序.在ASP.NET WEB中我使用了System.Web.Mvc,其中我有以下行来获取ControllerName:
descriptor.ControllerDescriptor.ControllerName 在ASP.NET Core 2.0中,这不起作用我收到错误:
在ASP.NET Core 2.0中,我找不到获取ControllerName的替代方法. 解决方法
您必须将ActionDescriptor实例强制转换为
ControllerActionDescriptor 实例才能访问ControllerName属性:
var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor; if (controllerActionDescriptor != null) { var controllerName = controllerActionDescriptor.ControllerName; } 相关:How to read action method’s attributes in ASP.NET Core MVC? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |