Return content with IHttpActionResult for non-OK response

前端 未结 15 2222
北恋
北恋 2020-11-28 17:55

For returning from a Web API 2 controller, I can return content with the response if the response is OK (status 200) like this:

    public IHttpActionResult          


        
15条回答
  •  鱼传尺愫
    2020-11-28 18:35

    I would recommend reading this post. There are tons of ways to use existing HttpResponse as suggested, but if you want to take advantage of Web Api 2, then look at using some of the built-in IHttpActionResult options such as

    return Ok() 
    

    or

    return NotFound()
    

    Choose the right return type for Web Api Controllers

提交回复
热议问题