一.post对象
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);
}
});
二。PostLIst
1.c#
public partial class tbl_OfficeSupplies_OrderDetailController : ApiController
{ /// <summary>
/// 新增详情
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
[HttpPost]
public HttpResponseMessage PostData1123(List<tbl_OfficeSupplies_OrderDetail> list)
{
if (list != null)
{
if (list.Count > 0)
{
foreach (tbl_OfficeSupplies_OrderDetail item in list)
{
tbl_OfficeSupplies_OrderDetail model = new tbl_OfficeSupplies_OrderDetail()
{
ID=Guid.NewGuid(),
GoodsID=item.GoodsID,
ProcurementApplyCount=item.ProcurementApplyCount,
OrderID=item.OrderID,
ProcurementPricePer=item.ProcurementPricePer,
CreateDate=DateTime.Now,
Creator=item.Creator,
GoodsSpecificationID=item.GoodsSpecificationID
};
Tbl_OfficeSupplies_OrderDetailBLL.AddEntity(model);
}
return Common.JsonHelper.toJson("ok");
}
return Common.JsonHelper.toJson("fail");
}
return Common.JsonHelper.toJson("fail"); }
}
2.js
var goodsList = [];
$.each(rows, function (index,item) {
var goods = {};
goods.GoodsID = item.GoodsID;
goods.ProcurementApplyCount = item.ProcurementApplyCount;
goods.ProcurementPricePer = item.ProcurementPricePer;
goods.Creator = app.userInfo.UserID;
goods.GoodsSpecificationID = item.GoodsSpecificationID;
goodsList.push(goods);
})
$.ajax({
url: app.webApi + 'tbl_OfficeSupplies_OrderDetail/PostData1123',
type: "post",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(goodsList),
success: function (data) {
if (JSON.parse(data).result == "ok") {
$.messager.alert('提示', '保存成功!', 'info');
$('#OfficeSuppliesProcurement').datagrid('reload');
} else {
alert(JSON.parse(data).result);
}
}
});
三:delete对象
后端:
// DELETE: odata/tbl_OfficeSupplies_GoodsSpecification(5)
/// <summary>
/// 删除tbl_OfficeSupplies_GoodsSpecification
/// </summary>
/// <param name="tbl_Base_Role"></param>
/// <returns></returns>
[HttpDelete]
public HttpResponseMessage Delete(tbl_OfficeSupplies_GoodsSpecification tbl_OfficeSupplies_GoodsSpecification)
{
if (Tbl_OfficeSupplies_GoodsSpecificationBLL.DeleteEntity(tbl_OfficeSupplies_GoodsSpecification))
{
return Common.JsonHelper.toJson(new { msg = "ok" });
}
else
{
return Common.JsonHelper.toJson(new { msg = "fail" });
}
}
前端:
var tbl_OfficeSupplies_Goods = {};
tbl_OfficeSupplies_Goods.ID = row.ID;
$.messager.confirm('提示', '确定删除吗?', function (r) {
if (r) {
$.ajax({
url: app.webApi + 'tbl_OfficeSupplies_GoodsSpecification/Delete',
type: 'DELETE',
data: tbl_OfficeSupplies_Goods,
success: function (data) {
$.messager.alert('提示', '删除成功!', 'info');
dg_GoodsSpecification.render();
},
error: function (XMLResponse) {
alert(XMLResponse.responseText);
}
});
}
});