2017-03-07 62 views
-3

如何将带有列表数据的'things'发送到控制器方法?除Bins Data外,我正在获取所有数据? Bins显示为空,计数为0.将列表从另一个列表从jquery传递到mvc中的控制器

即使我尝试了对bin和数据值进行了字符串处理,但没有奏效。

$(document).ready(function() { 

    var bins=[{'binName':testbiname,'isSelected':true}] 
     var things = [ 
      { id: 1, color: 'yellow',Bins:bins }, 
     ]; 



    things = JSON.stringify({ 'things': things }); 

    $.ajax({ 
     contentType: 'application/json; charset=utf-8', 
     dataType: 'json', 
     type: 'POST', 
     url: '/Home/PassThings', 
     data: things, 
     success: function() {   
      $('#result').html('"PassThings()" successfully called.'); 
     }, 
     failure: function (response) {   
      $('#result').html(response); 
     } 
    }); 
    }); 


    public void PassThings(List<Thing> things) 
    { 
     var t = things; 
    } 

    public class Thing 
    { 
     public int Id { get; set; } 
     public string Color { get; set; } 
    *public list<BinSelecter> Bins{get;set;}* 
    } 

public class BinSelecter 
{ 
public string binName {get;set;} 
public bool isSelected {get;set;} 
} 
+1

你的JavaScript事情并不包含任何垃圾箱对象 – Rick

+0

你可以展示BinSelecter的模型? – Usman

回答

0

让假设你BinSelecter具有以下属性

public class BinSelecter 
{ 
    public int Id { get; set; } 
    public string Color { get; set; } 
} 

,所以你可以把它添加到你的东西列表像

var Binsdata = [ 
    { id: 1, color: 'yellow' }, 
    { id: 2, color: 'blue' }, 
    { id: 3, color: 'red' } 
];  

var things = [ 
    { id: 1, color: 'yellow',Bins:Binsdata }, 
    { id: 2, color: 'blue',Bins:Binsdata}, 
    { id: 3, color: 'red',Bins:Binsdata } 
];  
相关问题