简体   繁体   English

将复杂的javascript对象传递给控制器​​。 对象列表始终为0

[英]Passing complex javascript object to controller. List of objects are always 0

I have a object that I am trying to pass to my C# controller. 我有一个要传递给C#控制器的对象。 All the properties get populated except the list I have is always count =0. 除了我拥有的列表始终为= 0之外,所有属性均已填充。 I have tried setting the header to content-type/json and Json.stringify. 我尝试将标头设置为content-type / json和Json.stringify。 Also for testing I am returning the product list from another call so I know that returns a list of products to my view that is formatted correctly. 另外,为了进行测试,我还从另一个调用返回了产品列表,所以我知道这会返回格式正确的产品列表到我的视图中。

example for creating request 创建请求的示例

 var request =
'Id':null, 
...
... rest of data is here standard properites
 ...
'Products':productlist

for product list I am currently using the return value from a call that returns a List 对于产品列表,我当前正在使用返回列表的调用的返回值

        return $http.post('api/Enty/Save', request )
        .error(function (data, status, headers, config) {
               errorLog('error: ' + data);
           });



public class Person:IPerson
{
    [Required]
    public int Id { get; set; }

    [MaxLength(90)]
    public String Address1 { get; set; }

    [MaxLength(90)]
    public String Address2 { get; set; }

    [MaxLength(40)]
    public String Address3 { get; set; }

    [MaxLength(40)]
    public String City { get; set; }

    [MaxLength(2)]
    public String State { get; set; }

    [MaxLength(40)]
    public String Province { get; set; }

    [MaxLength(10)]
    public String Zip { get; set; }

 public IList<IProduct> Products { get; set; }


}


    [HttpPost()]

    public Response Save(person r)
    {}

UPDATE 更新

If I make it List instead of IList it works. 如果我将其设为List而不是IList,则它可以工作。 Any ideas why? 有什么想法吗?

Turns out the issue was not the Ilist but the Iproduct. 原来问题不是Ilist,而是Iproduct。 I just changed to a concrete class for that property 我只是改成了那个财产的具体课程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Ajax从Controller方法将对象列表传递给JavaScript - Passing a list of objects to JavaScript from Controller method using Ajax 将 JavaScript 对象数组传递给控制器 - Passing JavaScript Array of Objects to Controller 将Javascript中的DataTable对象传递给控制器 - Passing a DataTable object in Javascript to controller 根据主 object 内另一个对象列表的属性值对复杂的 javascript 对象进行排序 - Sort complex javascript objects based on property value of another list of objects inside main object 将复杂对象从Angularjs控制器传递到MVC控制器不起作用 - Passing complex object from Angularjs controller to MVC controller is not working 使用 Ajax 将复杂对象数组从视图传递到控制器 - Passing array of complex objects from view to controller using Ajax 将对象数组分组并添加到复杂对象:Javascript - Grouping and adding array of objects to a complex object: Javascript FormData中的对象数组将0个对象传递给控制器 - Object array in FormData passing 0 objects to controller ASP.NET MVC通过Java序列化到Controller的AJAX通过BeginCollectionItem List的对象传递null - ASP.NET MVC Passing a BeginCollectionItem List's Object through AJAX with Javascript Serialize to Controller is passing null Javascript ajax 发布一个复杂对象,其中包含一组复杂对象 - Javascript ajax post a complex object with an array of complex objects inside
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM