action 中
model对象 的list集合作为参数,如图
那jq拼接json的格式我是这样写的
function ss() { var DishesComposition = '{"DishesComModel":['; $('.cailiaohide').each(function () { DishesComposition += '{ "id": "0", "pid": "' + modelid + '", "product": "' + modelname + '", "rid": "' + cailiaoid + '", "num": "' + nums + '", "ownership": "' + ownership + '" },';}); 拼接json字符串尾部 DishesComposition +=']}'; json字符串转为json集合 var dvalues = JSON.parse(DishesComposition); if (isvalide) { $.ajax({ type: "POST", cache: false, dataType: "json", url: "Combination", data: dvalues, success: function (result) { if (result.state == 'OK') { alert(result.msg); location.href = '/DishesComposition?ownership=' + ownership; } else { alert(result.msg); } }, error: function (result) { alert(result); } }); } }
这样action就能获取到 集合List<DishesComModel> DishesComModel 的参数,action方法的参数名要和json参数的key值,也就是
DishesComModel 一样。