我对 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 数组传递给服务器上的 Action,服务器以“”值不能为空来响应。参数名称:源”(因为数组在我的控制器中的操作上为空)。我尝试了所有可能的方法,但我找不到正确的方法。
我希望你能帮助我。
谢谢,贡萨洛。