如何将带有Bins数据列表的'东西'发送到控制器方法?我收到除Bins Data以外的所有数据? Bins显示为null,计数为0.
即使我尝试对字典和数据值进行字符串化,但也无效。
$(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;}
}
答案 0 :(得分: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 }
];