我正在尝试将基于视图的应用程序更改为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);
}
答案 0 :(得分:1)
OkObjectResult
是一个课程而非方法,您需要对其进行新的修改:return new OkObjectResult(model)
或使用helper method that exists on the controller:
return Ok(model);