Copy codeThe Code is as follows:
// Background
[HttpPost]
Public JsonResult CheckStock (IEnumerable <pvIdsCount> pvIds)
{
}
Public class pvIdsCount
{
Public int pvId {set; get ;}
Public int count {set; get ;}
}
// Front-end
$ (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", // use Post to pass values to complex objects,
Data: JSON. stringify ({pvIds: productIdCounntList}), // SON. stringify --- must for serialization
DataType: "json ",
ContentType: 'application/json; charset = UTF-8 ', // must
Error: function (){
Alert ("1 ");
},
Success: function (data ){
}