我正在用MVC5开发库存控制系统,我需要帮助,如何一键插入/更新主数据和明细数据?
就像下面的openERP图片

发布于 2019-04-23 20:20:38
我认为应该用json-jquery来完成。
var data=[{customerid:101,customername:'name',
detaile:[
{customerid:101,productid:1,product:'service1',desc:'any...',quantity:1,subtotal:100},
{customerid:101,productid:2,product:'service2',desc:'note ',quantity:2,subtotal:200}
]
}];
ajax request :
$.ajax({
url:'/urlcontroller/addDetail',
type: "POST",
data: data,
success: function (data, textStatus, jqXHR) {
alert('success');
}
, error: function (xhr, status, error) {
alert('error');
}
});Action中的参数应该是如下所示的类:
public class customer
{
public int customerid { get; set; }
public string customername { get; set; }
public customerdetail[] detaile { get; set; }
}
public class customerdetail
{
public int customerid { get; set; }
public int productid { get; set; }
public string product { get; set; }
public string desc { get; set; }
public int quantity { get; set; }
public int subtotal { get; set; }
}操作结果:
public jsonresult addDetail(customer records)
{
var db = new StorageContext();
db.customer.Add(records);
db.SaveChanges();
foreach (var item in records.detaile)
{
db.customerdetail.Add(item);
db.SaveChanges();
}
}https://stackoverflow.com/questions/34184593
复制相似问题