Select2 jquery プラグイン (MVC3、Razor、および Knockout JS を使用) と、ajax 呼び出しに渡したいカスタム パラメーターに問題があります。
私はこのコードを持っています:
$('#QuickSearchPresentation').select2({
placeholder: "Search for a movie",
minimumInputLength: 1,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: '@Url.Action("QuickSearchMainContainerFromPresentationByIdFolders", "DataCenter", new { amount = 10 })',
contentType: 'application/json',
dataType: 'json',
type: 'POST',
quietMillis: 400,
data: function (term, page) {
return ko.toJSON({
term: term,
idFolders: vm.Container.Catalogs
});
},
results: function (data, page) { // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter remote JSON data
console.log('results', data);
return {results: data};
}
},
initSelection: function(element, callback) {
console.log('element', element);
},
formatResult: containerQuickSearchResult, // omitted for brevity, see the source of this page
formatSelection: containerQuickSearchResult, // omitted for brevity, see the source of this page
dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
});
vm はノックアウト js からの私のモデルであり、カタログは int の配列です。
問題は、idFolders 配列をサーバー上のアクションに渡すことができないということです。サーバーは「値を null にすることはできません。パラメータ名:ソース」(コントローラのアクションで配列がnullになるため)。考えられるすべての方法を試してみましたが、正しい方法が見つかりません。
私はあなたがそれで私を助けてくれることを願っています.
ありがとう、ゴンザロ。