我创建了一个操作以返回项目中的所有控制器。
当我调试它显示给我4个项目时,但是当使用邮递员大摇大摆时,它仅显示一个项目。
控制器:
[HttpGet("GetControllerList")]
public async Task<IEnumerable<ControllerViewModel>> Get()
{
var asm = Assembly.GetExecutingAssembly();
var controller=await iMVCService.GetControllerDescovery(asm); ;
return controller;
}
和邮递员中的信息:
{"data":[{"areaName":null,"controllerAttributes":{"name":"مدیریت دسته بندی ها","shortName":null,"description":null,"prompt":null,"groupName":null,"resourceType":null
编辑:
MVCSErive:
public async Task<IEnumerable<ControllerViewModel>> GetControllerDescovery(Assembly assemblies)
{
var controllers = assemblies.GetExportedTypes()
.Where(t => typeof(ControllerBase).IsAssignableFrom(t))
.Select(t => new ControllerViewModel
{
ControllerAttributes = t.GetCustomAttribute<DisplayAttribute>(),
ControllerName = t.Name,
ControllerId = $"{t.Namespace} : {t.Name}"
})
.Where(x => x != null)
.ToList();
return controllers;
}
和我的视图模型:
public class ControllerViewModel
{
public string AreaName { get; set; }
//
// Summary:
// Returns the list of the Controller's Attributes.
public DisplayAttribute ControllerAttributes { get; set; }
//
// Summary:
// Returns the `DisplayNameAttribute` value
public string ControllerDisplayName { get; set; }
//
// Summary:
// It's set to `{AreaName}:{ControllerName}`
public string ControllerId { get; set; }
//
// Summary:
// Return ControllerActionDescriptor.ControllerName
public string ControllerName { get; set; }
}
可能是什么问题?