I have an API that is using .NET Core 3.1 Entity Framework.
I am getting data from a client side POST event that contains JSON with an array that looks like this:
"SpaceTrainees": [
"Pilot",
"Commander",
"Grunt"
]
My Controller that is handling the post event is throwing an error when it hits that array:
I am getting this error:
"$.SpaceTrainees[0]": [
"The JSON value could not be converted to System.Collections.Generic.List`1[System.Int64]. Path: $.SpaceTrainees[0] | LineNumber: 2 | BytePositionInLine: 21."
The code block in my controller that throws the error:
[HttpPost]
public async Task<ActionResult> ProcessRecruit([FromBody] CreateCadet data)
{
...
foreach (var traineeId in data.SpaceTrainees)
{ ... }
Return Ok();
}
--> where data.SpaceTrainees is of List
The model for CreateCadet contains a property:
public List<long> SpaceTrainees {get; set; }
Is there a way to make this work?
Thanks!
long
is a number, SpaceTrainees
is string[]
public List<string> SpaceTrainees {get; set; }
will work