1
Friends, I’m having trouble passing a value to the action of a specific controller that takes as parameter an id of type int.
AJAX
var dataForm = $("#statisticId").val();
$.ajax({
contentType: "application/json",
type: "POST",
url: "Statistic",
dataType: "json",
data: dataForm,
success: function (_response) {
console.log(_response);
}
});
Action Statistic
[HttpPost]
public IActionResult Statistic([FromBody]int dataForm)
{
var statistics = statisticPatientBLL.GetStatisticById(dataForm);
return Json(statistics);
}
I have checked if you are actually passing any value, and yes, it displays correctly when I collect the value of an HTML element. I couldn’t find an answer to that. Could anyone help me? Would it be a problem in the matter of routes? What’s wrong with this code?
George, I made the changes by following their structure, but I couldn’t get the id value. What might be in this case?
– Felipe Prestes
@Felipeprestes, I realized now that I left this date part: id, no comma, I just edited and put it, must be this.
– George Wurthmann