复制代码 代码如下:
//后台
[httppost]
public jsonresult checkstock(ienumerable<pvidscount> pvids)
{
}
public class pvidscount
{
public int pvid { set; get; }
public int count { set; get; }
}
//前台
$(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,
data: json.stringify ({ pvids: productidcounntlist }), //son.stringify ---must 用来序列化
datatype: "json",
contenttype: 'application/json; charset=utf-8', //must
error: function () {
alert("1");
},
success: function (data) {
}