Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ExtJs/.Net-将批处理Json数据转换为.Net类型时出错_C#_.net_Json_Asp.net Mvc_Extjs - Fatal编程技术网

C# ExtJs/.Net-将批处理Json数据转换为.Net类型时出错

C# ExtJs/.Net-将批处理Json数据转换为.Net类型时出错,c#,.net,json,asp.net-mvc,extjs,C#,.net,Json,Asp.net Mvc,Extjs,我有一个带有ExtJS前端的.NETMVC应用程序。我正在尝试更新网格中的多个记录。记录将作为带有Ext.Direct代理的模型传递,该代理与此.Net类型匹配: public class AgreementType { public int AgreementTypeId { get; set; } public string Value { get; set; } public bool IsDeleted { get; set; } } 这就是我要介绍的方法: p

我有一个带有ExtJS前端的.NETMVC应用程序。我正在尝试更新网格中的多个记录。记录将作为带有
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对象(例如{“name”:“value”})才能正确反序列化。 要修复此错误,请将JSON更改为JSON对象(例如{“name”:“value”}),或将反序列化类型更改为数组或实现可从JSON数组反序列化的集合接口(例如ICollection、IList)类似列表的类型。还可以将JsonArrayAttribute添加到类型中,以强制它从JSON数组反序列化。 路径“”,第1行,位置1

当我尝试传递一条记录时,它会将数据正确解释为我的类型并成功更新。编辑:以下是该项目的有效载荷:

{"action":"Main","method":"UpdateAgreementType","data":[{"AgreementTypeId":11,"Value":"PROCARD-test","IsDeleted":false}],"type":"rpc","tid":12}

我对json有点不了解,但我认为数据格式有问题。我尝试显式地传递值,而不仅仅是传递模型,但这不起作用。有什么建议吗?

你不仅仅有一个
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; }
}
此有效负载工作正常:{“操作”:“主”、“方法”:“UpdateAgreementType”、“数据”:[{“AgreementTypeId”:11,“值”:“PROCARD测试”、“IsDeleted”:false}],“类型”:“rpc”、“tid”:12}