Ajax to jsond MVC background receiving instance

Time:2021-9-20
Copy codeThe code is as follows:
//Backstage
[HttpPost]
public JsonResult CheckStock(IEnumerable<pvIdsCount> pvIds)
{
}
public class pvIdsCount
{
public int pvId { set; get; }
public int count { set; get; }
}
//Front desk
$(document).ready(function () {
$(‘#checkout’).click(function ()
{
var productIdCounntList = [];
var allPvId = $(“.productVariantIdAll”);
$.each(allPvId, function (index, data) {
var productIdCounnt = { pvId: data.getAttribute(“data-Id”), count: data.getAttribute(“data-Count”)};
productIdCounntList.push(productIdCounnt);
});
$.ajax({
url:”@Url.Action(“CheckStock”)”,
Type: “post”, / / post is used for complex object value transfer,
Data: JSON. Stringify ({pvids: productidcounntlist}), / / son.stringify — must used to serialize
dataType: “json”,
contentType: ‘application/json; charset=utf-8’, //must
error: function () {
alert(“1”);
},
success: function (data) {
}