dem*_*key 8 c# asp.net-web-api
我已经开始IHttpActionResult使用[ResponseType]属性来装饰我的方法,目的是让消费者更容易知道如何处理响应.
这对GET来说很有意义,因为我可能想要对返回的数据做些什么.
但[ResponseType]对PUT或POST请求有什么意义,它们不返回任何数据,只是成功代码?
例如
[HttpPut]
[Route("Contact/{contactId:int}/name", Name = "UpdateContactName")]
[ResponseType(typeof(?????))] // <- what should I put here? do I even need it at all?
public IHttpActionResult UpdateName(int contactId, [FromBody] string name)
{
//...
return StatusCode(HttpStatusCode.Accepted);
}
Run Code Online (Sandbox Code Playgroud)
dem*_*key 12
事实证明,[ResponseType] 确实使控制器上的方法不返回数据的意义.
您可以使用void类型来确保WebApi帮助文件不会为这些方法显示"示例不可用"消息.
即
[ResponseType(typeof(void))]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5628 次 |
| 最近记录: |