I have Ajax list array in razor, which will post to controller, but my problem is why always 0 list when i post to contoller.
var FoodList = [];
$('#table-information > tbody > tr').each(function () {
var Food = {};
Food.food_id = this.cells[0].innerHTML;
Food.food_name = this.cells[1].innerHTML;
Food.price = this.cells[2].innerHTML;
Food.Quantity = this.cells[3].innerHTML;
FoodList.push(Food);
});
//alert(JSON.stringify(FoodList));
$.ajax({
url: '/Transaction/Order',
type: "POST",
data: JSON.stringify(FoodList),
contentType: "application/json",
dataType: "json",
success: function (response) {
if (response === true) {
alert("Order have been saved successfully.");
//ClearForm();
$('#table-body').empty();
CheckSubmitBtn();
} else {
alert("Ooops, an error has ocurrer while processing the transaction.");
}
}
});
[HttpPost]
public JsonResult Order(List<Food> FoodList)
{
var email = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "Email")?.Value;