I have a code like this:
public IHttpActionResult Post(CUSTOMER [] newCustomer)
{
try
{
foreach (CUSTOMER item in newCustomer)
{
var AddedCust = db.CUSTOMERs.Add(item);
}
int insertedRecords = db.SaveChanges();
return Ok(insertedRecords);
}
catch (Exception)
{
return BadRequest(ModelState);
}
}
With Postman I am trying to post more than one record - but I get an exception:
{
"NAME": "test1",
"SURNAME": "Aleksandrova",
"BIRTHPLACE": "Minsk",
"GENDER": "F",
"IDENTITYNO": "AA75 857445",
"IDENTITYPINCODE": 2552,
"BIRTHDATE": "1970-06-19T00:00:00"
}
{
"NAME": "test2",
"SURNAME": "Aleksat34t34ndrova",
"BIRTHPLACE": "Minsk",
"GENDER": "F",
"IDENTITYNO": "AA75 857445",
"IDENTITYPINCODE": 2552,
"BIRTHDATE": "1970-06-19T00:00:00"
}
{
"NAME": "test3",
"SURNAME": "Aleksandrova",
"BIRTHPLACE": "Minsk",
"GENDER": "F",
"IDENTITYNO": "AA75 857445",
"IDENTITYPINCODE": 2552,
"BIRTHDATE": "1970-06-19T00:00:00"
}
ERROR:
"Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'First_API.Models.CUSTOMER[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object.
How can I solve this problem?