2017-08-23 69 views
-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传递

+0

你在浏览器控制台中是否有错误?你也不必使用stringify,你正在传递json –

+0

@ N.Ivanov不,只是一个null模型服务器端 – ancdev

+0

在ajax之前做一个'console.log(serializableFilter)',看看是否一切正常 –

回答

0

我想知道filter.includeBranches的类型是否真的是bool。 你为什么不试试这个:

serializableFilter.includeBranches = filter.includeBranches==true; 
+0

这就是它的填写方式'filter.includeBranches = document.getElementById('option-branches “).checked' – ancdev