Ho un'API che utilizza .NET Core 3.1 Entity Framework.
Ricevo dati da un evento POST lato client che contiene JSON con un array simile al seguente:
"SpaceTrainees": [
"Pilot",
"Commander",
"Grunt"
]
Il mio controller che gestisce l'evento post sta generando un errore quando colpisce quell'array:
Ricevo questo errore:
"$.SpaceTrainees[0]": [
"The JSON value could not be converted to System.Collections.Generic.List`1[System.Int64]. Path: $.SpaceTrainees[0] | LineNumber: 2 | BytePositionInLine: 21."
Il blocco di codice nel mio controller che genera l'errore:
[HttpPost]
public async Task<ActionResult> ProcessRecruit([FromBody] CreateCadet data)
{
...
foreach (var traineeId in data.SpaceTrainees)
{ ... }
Return Ok();
}
-> dove data.SpaceTrainees è nell'elenco
Il modello per CreateCadet contiene una proprietà:
public List<long> SpaceTrainees {get; set; }
C'è un modo per farlo funzionare?
Grazie!
long
è un numero, SpaceTrainees
è string[]
public List<string> SpaceTrainees {get; set; }
funzionerà