模型里的list字段接收不到ajax传来的数据怎么办,不知道问题出现在哪里,或者是我定义模型出错、还是ajax传值方式有问题。
js代码:前台因为品种对象为不确定数据,所以自定义了一个list<FaermerIcitemEntry>来接收,js代码是这样的:
var model = {};
var data = {};
model["FarmerName"] = "张三";
model["Number"] = '18789738178';
model["Environment"] = "运动场";
//获取品种id
$("input:checked[name=BreedId]:checked").each(function () {
var BreedId = $(this).val(); //1000,1005
arr1.push(BreedId);
});
//获取数量
$("input[name=Amount]").each(function () {
arr2.push($(this).val()); //1300,1200
});
//遍历使用data数组存储品种:数量
for (var i = 0; i < arr1.length; i++) {
data[arr1[i]] = arr2[i];
}
model.entrys = data; //将品种数量赋值给model
控制台数据
后台接收时,其他字段都有数据,但是entrys这个list字段却为null
模型定义:
/// <summary>
/// 养户对象
/// </summary>
public class FarmerIcitemModel
{
public int FarmerIcitemId { get; set; }
public string FarmerName { get; set; }
public string Number { get; set; }
public string FarmerAddress { get; set; }
public string Environment { get; set; }
public Nullable<int> Area { get; set; }
public List<FaermerIcitemEntry> entrys { get; set; }
}
/// <summary>
/// 品种对象
/// </summary>
public class FaermerIcitemEntry
{
//public int FaEntryId { get; set; }
public int? BreedId { get; set; }
public int? FarmerIcitemId { get; set; }
public string BreedName { get; set; }
public Nullable<int> Amount { get; set; }
}