-1
After receiving a CSV file and reading it with the JS Filereader, I need to send the return of this reading to an Action of a C#Controller. However when sending, I get an error 400. I would like to know a way to send this data to the back end and correct this error. Below are the codes :
JS function to read CSV.
function lerCSV() {
var reader = new FileReader();
reader.onload = function () {
var resultado = reader.result;
console.log(resultado);
$.ajax({
url: "/Dashboard/" + productId + "/Coupons/GenerateTable",
type: "POST",
dataType: "json",
contentType: 'application/json; charset=utf-8',
data: '{resultado:'+ resultado + '}',
success: function (result) {
alert('Concluido');
}
});
};
//start reading the file. When it is done, calls the onload event defined above.
reader.readAsText(planilha.files[0]);
}
Action C#
public IActionResult GenerateTable(string resultado)
{
return Json("Concluido");
}
Was able to test?
– Leandro Angelo
So @Leandroangelo tested, but continues with bad request error.
– Gabriel R. Romão
Now I get it, you didn’t prepare your controller to receive a json
– Leandro Angelo
What I should receive as a parameter in Action?
– Gabriel R. Romão
Watch the answer edit, but don’t just copy and paste. Try to understand what you’re doing and what’s going on ;)
– Leandro Angelo
Managed to solve?
– Leandro Angelo