当我创建控制器并继承ApiController时,我正在使用.net core 2.1。但是在我的控制器方法中,返回类型HttpResponseMessage并给定错误,给出问题标题,这是我的方法
[HttpGet]
[Route("GetAll")]
[AcceptVerbs("Get", "Post")]
public HttpResponseMessage SelectCAllCustomers()
{
try
{
return Request.CreateResponse<List<Customer>>(HttpStatusCode.OK, customerDetailsRepository.FindAll("SelectAllCustomers").ToList());
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
}
}
答案 0 :(得分:4)
Asp.Net Core不再使用该API。
使用更新的语法
[Route("api/[controller]")]
public class CustomersController: Controller {
//...
[HttpGet("GetAll")]
[AcceptVerbs("Get", "Post")]
public IActionResult SelectCAllCustomers() {
var model = customerDetailsRepository.FindAll("SelectAllCustomers").ToList();
return Ok(model);
}
}