0
I’m having trouble passing an array to a controller via Axios.
Example of the WEBAPI Controller code:
[HttpGet]
[ActionName("openshape")]
[Route("api/shape/openshape")]
public IEnumerable<Fields> OpenShape(FileOpen[] path)
When I send the request to React it arrives null
in the WEBAPI.
Example of the method in React:
var path = [];
var ListSelect = Object.assign([], e.target.files);
for(var i = 0; i < ListSelect.length; i++){
let result = { data:'', fileName:''}
var reader = new FileReader();
reader.readAsDataURL(ListSelect[i]);
reader.onload = e => {
result.data = e.target.result.toString();
}
result.fileName = ListSelect[i].name;
path.push(result);
}
let obj = await api.get("/shape/openshape/", {params: {path: path}})
Example of the Fileopen class:
public class FileOpen
{
public string Data { get; set; }
public string fileName { get; set; }
}
It worked, but now the error is in the conversion of the array to JSON. .
– Michel Oliveira
the problem may be because of the indentation of the Json content, take a look at the documentation at https://www.newtonsoft.com/json/help/html/NamingStrategyCamelCase.htm
– Julio Borges
I managed to fix. The problem was at the time of reading the Reader.onload, because it loads the data but after I add it in the list the values magically disappears kkk so I changed the structure, letting the user upload the two files manually one at a time.
– Michel Oliveira