不可用的OkObjectResult不能像方法一样使用
问题描述:
我试图将基于视图的应用程序更改为API。 关闭此项目here。我不能退还OkObjectResult
。为什么会这样呢,为什么ASP的价格是IActionResult
vs ActionResult
?不可用的OkObjectResult不能像方法一样使用
[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);
}
答
OkObjectResult
是一类不是一个方法,你需要新的它:return new OkObjectResult(model)
或使用helper method that exists on the controller:
return Ok(model);