2017-03-07 25 views
-3

Binsデータのリストを「もの」にコントローラメソッドに送る方法は?私はBins Data以外のすべてのデータを取得していますか? Binsは0とカウントされてnullとして表示されています。mvcのjqueryからコントローラのリストを別のリストに渡す

でも、私はビンとデータ値の両方をストリング化しようとしましたが機能しませんでした。

$(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 } 
];  
関連する問題