-1
我有下面的代码,直到我添加了最后一个属性它完美罚款在JS对象ASP NET内核MVC阿贾克斯后
JS:
var serializableFilter = {};
serializableFilter.aosType = filter.aos.type;
serializableFilter.aosText = filter.aos.text;
serializableFilter.industries = filter.industries.getCommaSeperatedIDs();
serializableFilter.servicingBanks = filter.servicingBanks.getCommaSeperatedIDs();
serializableFilter.category = filter.categories.categoryID;
serializableFilter.yearEstablishedFrom = filter.yearEstablished.from;
serializableFilter.yearEstablishedTo = filter.yearEstablished.to;
serializableFilter.staffMin = filter.nbStaff.min;
serializableFilter.staffMax = filter.nbStaff.max;
//serializableFilter.includeBranches = filter.includeBranches;
$.ajax({
url: url,
type: "POST",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(serializableFilter),
success: function (result) {
console.log(result);
},
error: function() {
alert('error');
}
});
C#:
[HttpPost]
public async Task<IEnumerable<FdxxxMap>> GetC([FromBody] Filter data)
型号:
public class Filter
{
public string aosType { get; set; }
public string aosText { get; set; }
public string industries { get; set; }
public string servicingBanks { get; set; }
public int category { get; set; }
public int yearEstablishedFrom { get; set; }
public int yearEstablishedTo { get; set; }
public int staffMin { get; set; }
public int staffMax { get; set; }
public Boolean includeBranches { get; set; }
}
Whe从来没有添加布尔类型的最后一个属性,数据模型作为NULL传递
你在浏览器控制台中是否有错误?你也不必使用stringify,你正在传递json –
@ N.Ivanov不,只是一个null模型服务器端 – ancdev
在ajax之前做一个'console.log(serializableFilter)',看看是否一切正常 –