Json Web API HttpPost能否返回ICollection

Json Web API HttpPost能否返回ICollection,json,web-services,asp.net-web-api,http-post,Json,Web Services,Asp.net Web Api,Http Post,新手编写Web服务。我将C#/ASP.Net与WebAPI一起使用。最终目标是接收JSON收集,将数据反序列化到数据库,并将任何失败的记录通知客户端应用程序,客户端将记录这些记录 HTTPPost是否可以通过IHttpActionResult或HttpResponseMessage返回失败行的集合(作为序列化Json),类似这样: [HttpPost] public HttpResponseMessage Post([FromBody]List<Things> t) { //

新手编写Web服务。我将C#/ASP.Net与WebAPI一起使用。最终目标是接收JSON收集,将数据反序列化到数据库,并将任何失败的记录通知客户端应用程序,客户端将记录这些记录

HTTPPost是否可以通过IHttpActionResult或HttpResponseMessage返回失败行的集合(作为序列化Json),类似这样:

[HttpPost]
public HttpResponseMessage Post([FromBody]List<Things> t)
{
    // deserialize t and process to database

    // list of failed records
    ICollection<Thing> things= new List<Thing>();
    things.Add(...);
    things.Add(...);

    string jsonFailedRows = 
      JsonConvert.SerializeObject(things, Formatting.Indented);

    // Write the list to the response body
    HttpResponseMessage response =     
       Request.CreateResponse(HttpStatusCode.OK, jsonFailedRows);
    return response;
}

最后,有没有办法使用CreatedAtRoute来实现这一点?

链接回复中发布的解决方案确实回答了这个问题

return Ok(jsonFailedRows);