我通过AJAX调用将一个json数据列表传递给控制器。 字符串数组“LandPhone,Mobile和Email”在控制器中变为null。实际上有一些价值观。
主要模式
public class CustomerModel
{
public string ReferenceId { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string TINNo { get; set; }
public string CurrencyId { get; set; }
public List<CustomerAddressModel> Address { get; set; }
}
子模型
public class CustomerAddressModel
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string AddressLine3 { get; set; }
public int ZipCode { get; set; }
public string District { get; set; }
public string State { get; set; }
public string Country { get; set; }
public string[] LandPhone { get; set; }
public string[] Mobile { get; set; }
public string[] Email { get; set; }
}
AJAX致电
function get() {
$.ajax({
type: 'POST',
url: '/temp/Customer',
data: { "ReferenceId": "", "FirstName": "", "MiddleName": "", "LastName": "", "TINNo": "", "CurrencyId": 0,
"Address": [{
"AddressLine1": "", "AddressLine2": "", "AddressLine3": "", "ZipCode": 0, "District": "", "State": "", "Country": "",
"LandPhone": ["123"],
"Mobile": ["1234567890", "9876543210"],
"Email": ["a@b.com", "b@c.com"]
}]
},
dataType: "json",
//contentType: "application/json;charset=utf-8",
async: false,
success: function (data) {
alert(data);
}
});
在控制器方法数据中得到这样的
答案 0 :(得分:5)
您需要包含filename
选项并对数据进行字符串化
None