C# 前段传模型和集合,后台直接用Model和List 接收
/*******在前段拼接Model,后台直接用模型类去接收************/
//前端 --1
var data = [];
data.push({ name: 'Id', value: "123" }),
data.push({ name: 'Overage', value: "3%" }),
data.push({ name: 'SampleQty', value: "143" }),
data.push({ name: 'Qty', value: "123" }),
//异步提交(直接传data数组不用转换和指定后台接收的变量名称)--2
$.ajax({
url: "/order/RfidOrder/ChangeDetailInfoee",
data: data,
success: function (data) {
}
});
//后台定义接收--3
[Route("ChangeDetailInfoee")]
[ValidateInput(false)]
public void ChangeDetailInfoee(ListOption option)
{
}
/******直接在前段传List集合,后台用集合去接收,用索引更新Name****
//前端--1
var data = [];
data.push({ name: 'option[0].Id', value: "123" }),
data.push({ name: 'option[0].Overage', value: "3%" }),
data.push({ name: 'option[0].SampleQty', value: "143" }),
data.push({ name: 'option[0].Qty', value: "123" }),
data.push({ name: 'option[1].Id', value: "124" }),
data.push({ name: 'option[1].Overage', value: "4%" }),
data.push({ name: 'option[1].SampleQty', value: "144" }),
data.push({ name: 'option[1].Qty', value: "124" })
//异步提交(通过指定后台对应接收的变量名称利用索引来对List集合进行填充)--2
$.ajax({
url: "/order/RfidOrder/ChangeDetailInfoee",
data: data,
success: function (data) {
}
});
//后台定义接收--3
[Route("ChangeDetailInfoee")]
[ValidateInput(false)]
public void ChangeDetailInfoee(List<ListOption> option)
{
}
/*********ListOption********/
public class ListOption
{
public string Id { get; set; }
public string Overage { get; set; }
public string SampleQty { get; set; }
public string Qty { get; set; }
}
上一篇: 同桌的屁股