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

时间:2017-10-19 23:00:02

标签: c# asp.net-core

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

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

[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);
}

1 个答案:

答案 0 :(得分:1)

OkObjectResult是一个课程而非方法,您需要对其进行新的修改:return new OkObjectResult(model)或使用helper method that exists on the controller

return Ok(model);