1.后台c#
public class TestController : ApiController { [HttpPost] public string SaveData1(Tb_a ota) { return ota.aa.ID + ota.bb.FirstOrDefault().NAME; } /// <summary> /// /// </summary> /// <param name="ota"></param> /// <returns></returns> [HttpPost] public bool SaveData(Tb_a ota) { return true; } } public class Tb_a { public TB_CHARGING aa { get; set; } public List<TB_CHARGING> bb { get; set; } }
2.前端js
var postData = { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }; var postData1 = [{ ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }, { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }]; $.ajax({ type: "post", url: ApiUrl + "api/Test/SaveData", data: { aa: { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }, bb: [{ ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }, { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }] }, success: function (data, status) { } }); $.ajax({ type: "post", url: ApiUrl + "api/Test/SaveData1", data: { aa: postData, bb: postData1 }, success: function (data, status) { alert(data); } });