[英]ASP.NET Web API Action Results
When we use a HttpGet
action method to get resources we generally return Ok()
. 当我们使用
HttpGet
操作方法获取资源时,通常返回Ok()
。
public IHttpActionResult Get() {
var customers = context.customers.toList();
return Ok(customers);
}
When we use HttpPost
action method to create a record we return Created() with the location of the newly created resource. 当我们使用
HttpPost
操作方法创建记录时,我们将返回Created()以及新创建的资源的位置。
When we use HttpPut
to update a record what do we return? 当我们使用
HttpPut
更新记录时,我们返回什么? For example when we read records we return Ok()
and for create we return Created()
例如,当我们读取记录时,我们返回
Ok()
;对于create,我们返回Created()
And also what do we return for HttpDelete
? 还有,我们为
HttpDelete
返回什么?
根据https://docs.asp.net/zh/latest/tutorials/first-web-api.html中的教程,当您执行HTTP PUT
或HTTP DELETE
您必须返回204 (No content)
代码。
return new NoContentResult();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.