C# 不可调用的OkObjectResult不能像方法一样使用

C# 不可调用的OkObjectResult不能像方法一样使用,c#,asp.net-core,C#,Asp.net Core,我正在尝试将基于视图的应用程序更改为API。 完成这个项目 我无法返回OkObjectResult。为什么会这样,为什么ASP会移动到IActionResult vs ActionResult OkObjectResult是一个类而不是一个方法,您需要重新创建它:返回新的OkObjectResultmodel或使用: [HttpGet] public IActionResult Index() { List<ApplicationRoleListViewModel> mode

我正在尝试将基于视图的应用程序更改为API。 完成这个项目

我无法返回OkObjectResult。为什么会这样,为什么ASP会移动到IActionResult vs ActionResult

OkObjectResult是一个类而不是一个方法,您需要重新创建它:返回新的OkObjectResultmodel或使用:

[HttpGet]
public IActionResult Index()
{
    List<ApplicationRoleListViewModel> model = new List<ApplicationRoleListViewModel>();
    model = roleManager.Roles.Select(r => new ApplicationRoleListViewModel
    {
        RoleName = r.Name,
        Id = r.Id,
        Description = r.Description,
        NumberOfUsers = r.Users.Count
    }).ToList();
    return OkObjectResult(model);
}
return Ok(model);