简体   繁体   中英

Web api: [FromBody] always returns list with count of 0

I have an api (post method) that takes in a list of transport objects. when I test using swagger, the list comes back with a count of 0 (not null), even though I am sending a List of transports. In below scenario I would assume the count should be 1. Here is a small sample of the Json I am sending.

[{
  "type": "",
  "attributes": {
    "TransportId":"",
    "Status": "string",
    "Action": "test",
    "ActionBy": "string",
    "ActionDate": "",
    "PackingGroupID": "a713eb0a-5682-4cb5"}]

Here is the api call:

[HttpPost, Route("bulk")]
[ResponseType(typeof(List<Transport>))]
public async Task<IHttpActionResult> SaveTransports([FromBody] List<Transport> transports, string packingGroupId)
{      
    var resulttransports = await _transportService.SaveTransportsAsync(transports, packingGroupId);
    if (resulttransports != null)
        ConvertTransportDateToTimezone(ref resulttransports);
    return Ok(resulttransports);
}

Bel:ow is an image of result

结果的形象

Try adding one more } at the end. I use JsonFormatter to always test my JSON.

https://jsonformatter.curiousconcept.com/#

   [{
  "type": "",
  "attributes": {
    "TransportId":"",
    "Status": "string",
    "Action": "test",
    "ActionBy": "string",
    "ActionDate": "",
    "PackingGroupID": "a713eb0a-5682-4cb5"}}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM