C# 如何在WebApi Odata上将对象列表作为参数传递?
我在WebApi Odata上将对象列表作为参数传递时遇到问题。 我有两门课:C# 如何在WebApi Odata上将对象列表作为参数传递?,c#,asp.net-mvc,asp.net-web-api,odata,C#,Asp.net Mvc,Asp.net Web Api,Odata,我在WebApi Odata上将对象列表作为参数传递时遇到问题。 我有两门课: public class Test{ public int Id {get; set;} public string Desc {get; set;} public Tests[] Tests{ get; set; } } public class Tests{ public int Entry1 {get; set;} public int Entry2 {get; set;}
public class Test{
public int Id {get; set;}
public string Desc {get; set;}
public Tests[] Tests{ get; set; }
}
public class Tests{
public int Entry1 {get; set;}
public int Entry2 {get; set;}
}
在客户端,im将参数作为对象传递:
var postData = {
onTest: {
id: data.Id,
desc: data.Desc
tests: data.Tests // here there is list of two objects
}
};
在WebApiConfig上:
builder.EntitySet<Test>("Tests");
var onTest = builder.EntityType<Test>().Collection.Action("UpdateTest");
onTest .EntityParameter<Test>("onTest");
builder.EntitySet(“测试”);
var onTest=builder.EntityType().Collection.Action(“UpdateTest”);
onTest.实体参数(“onTest”);
当我只发送Id和Desc时,它们被传递给控制器操作ok,但当我包含测试列表时,收到的参数为null
有什么建议吗?如何通过参数将对象列表测试传递给控制器?试试以下方法:
onTest.CollectionEntityParameter<Test>("onTests");
onTest.CollectionEntityParameter(“onTest”);
仅供参考相关文档:尝试以下方法:
onTest.CollectionEntityParameter<Test>("onTests");
onTest.CollectionEntityParameter(“onTest”);
供参考的相关文件: