2017-08-23 10 views
-1

私は、次のコードを持っていると私はASPネットコアMVCのAjaxポスト

JS 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私はboolean型の最後のプロパティを追加したことがない、データモデルはfilter.includeBranchesの種類は本当にブールあるかしらヌル

+0

あなたのブラウザのコンソールにエラーが発生しますか?すべてが微 –

+0

を渡している文字列化を使用する必要はいけない、ちょうどヌルモデルのサーバ側 – ancdev

+0

は、Ajaxの前に ''はconsole.log(serializableFilter)を行う、と見ます'filter.includeBranches'はおそらくその何か他のものなので、C#はブール値に変換できません –

答えて

0

として渡されます。 なぜあなたはこれを試してみませんか:

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

:{serializableFilter「データを」} ').checked' – ancdev

関連する問題