我正在尝试将一个简单的对象(AjaxSubmission)从表单发送到用于编辑表的Web API控制器。
AjaxSubmission始终具有相同的字段。一个字段,"数据"是指具有特定表的访问器的另一个简单对象(下面的Employees或Vendors示例)。
public class AjaxSubmission
{
public string action { get; set; }
public string table { get; set; }
public string id { get; set; }
// ...
//// The following may be any other custom class
public Employees data { get; set; } // Could be Vendors or whatever
}
// Stored in AjaxSubmission (or so I hope)
public class Employees
{
public string name { get; set; }
public float salary { get; set; }
public long id { get; set; }
}
// Stored in AjaxSubmission
public class Vendors
{
public string dba { get; set; }
public int accountNum { get; set; }
public int zipcode { get; set; }
}
我的控制器获得如下数据:
public EditorServerResponse Put(AjaxSubmission ajaxSubmission = null) {
// Handle the data
}
我的问题是:如何在不重复自己的情况下发送AjaxSubmission? .NET能够做到这一点吗?
编辑: Fiddler说数据看起来像:
action edit
table
id row_4
data[amu] 49
data[chemicalFormula] BF2
data[commonName] Boron difluoride
data[status] Y
data[notes]
原始数据是: 行动=编辑&安培;表=安培; ID = row_4&安培;数据%5Bamu%5D = 49&安培;数据%5BchemicalFormula%5D = BF2&安培;数据%5BcommonName%5D =硼+氟&安培;数据%5Bstatus%5D = Y&安培;数据%5Bnotes% 5D =
(这与我的简化示例不同,但类似)