var newRecords = [];
values: [
{
"id": 7,
"name": "Raddish",
"rate": 30,
"weight": "5",
"amountperweight": 150
},
{
"id": 8,
"name": "Peas",
"rate": 35,
"weight": "6",
"amountperweight": 210
}
]
$.ajax({
method: "post",
url: "http://localhost:36551/Orders/GenerateOrder",
data: { "values": newRecords },
dataType: "json",
success: function (response) {
},
error: function (error) {
}
});
[HttpPost]
[Route("GenerateOrder")]
[ActionName("GenerateOrder")]
public List<OrderCart> GenerateOrder(List<OrderCart> generateOrder)
{
return generateOrder;
}
Asked
Active
Viewed 404 times
-2
-
Code does not seem to have anything to do with title... Are you sure you've posted correct code? And please add an explanation... – Alexei Levenkov Apr 30 '20 at 21:27
1 Answers
0
On your javascript, make sure also that newRecords is equals to the following like this before you even call the ajax post.
newRecords = [{ "id": 7, "name": "Raddish", "rate": 30, "weight": "5", "amountperweight": 150 }, { "id": 8, "name": "Peas", "rate": 35, "weight": "6", "amountperweight": 210 }];
Your js property name does not correspond directly to your controller action's property name. On your javascript block, change your
data: { "values": newRecords },
to
data: { "generateOrder": newRecords },

Markuzy
- 483
- 6
- 10
-
I have replaced data: { "values": newRecords }, to data: { "generateOrder": newRecords }, i am passing same about newRecords array values but result is "Count=0". – Dani May 01 '20 at 12:16