我有一个带有.Net前端的ExtJS mvc应用程序。我试图从一个网格中更新多个记录。这些记录将作为一个具有Ext.Direct代理的模型传递,该代理与此.Net类型匹配:
public class AgreementType
{
public int AgreementTypeId { get; set; }
public string Value { get; set; }
public bool IsDeleted { get; set; }
}这是我要传递的方法:
public ActionResult UpdateAgreementType(AgreementType at)
{
return Json(new
{
success = _vendorRepo.UpdateAgreementType(at)
});
}这是请求有效载荷:
{"action":"Main","method":"UpdateAgreementType","data":[[{"AgreementTypeId":10,"Value":"Spot PO","IsDeleted":false},{"AgreementTypeId":11,"Value":"PROCARD-test","IsDeleted":false}]],"type":"rpc","tid":12}我得到了一个错误:
无法将当前JSON数组(例如,1,2,3)反序列化为'Project.Model.AgreementType‘类型,因为该类型需要一个JSON对象(例如{“名称”:“值”})才能正确反序列化。要修复此错误,要么将JSON更改为JSON对象(例如,{"name":"value"}),要么将反序列化类型更改为数组,或者将实现集合接口(例如ICollection、IList)的类型改为可以从JSON数组反序列化的列表。还可以将JsonArrayAttribute添加到该类型中,以强制它从JSON数组中反序列化。路径'',第1行,位置1。
当我试图传递一条记录时,它将正确地将数据解释为我的类型并成功地进行更新。编辑:这是它的有效负载:
{"action":"Main","method":"UpdateAgreementType","data":[{"AgreementTypeId":11,"Value":"PROCARD-test","IsDeleted":false}],"type":"rpc","tid":12}我对json有点不太在行,但我认为数据格式有问题。我尝试显式地传递值,而不是仅仅传递模型,但这是行不通的。有什么建议吗?
发布于 2018-12-21 17:56:39
您不仅有一个AggreementType,还有一个由JSON有效负载描述的复杂得多的对象。粘成类看起来是这样的:
public class Rootobject
{
public string action { get; set; }
public string method { get; set; }
public Datum[][] data { get; set; }
public string type { get; set; }
public int tid { get; set; }
}
public class Datum
{
public int AgreementTypeId { get; set; }
public string Value { get; set; }
public bool IsDeleted { get; set; }
}https://stackoverflow.com/questions/53888956
复制相似问题