Curious-programmer
Curious-programmer

Reputation: 813

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

Image of result

Upvotes: 0

Views: 831

Answers (1)

JohnPete22
JohnPete22

Reputation: 523

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"}}]

Upvotes: 1

Related Questions