我正在使用datatable.js
和MVC4 Web应用程序。我试图在fnServerParams
中传递数组数据。
这里我创建了一个名为array
的数组对象,用于将数据传递到服务器端。
请参阅下面的代码:
function GetTaxInvoices(IsInital, TaxInvoiceIds) {
alert("message : IsInital :- " + IsInital + " , TaxInvoiceIds :- " + TaxInvoiceIds);
var elementName = "#tblCreatedTaxInvoices";
ClearData(dtTable2);
var array = [51, 52];
ajaxUrl = (IsInital) ? null : '@Url.Action("GetCreatedTaxInvoices", "Invoice")';
dtTable2 = $(elementName).dataTable({
bProcessing: true,
bLengthChange: false,
sAjaxSource: ajaxUrl,
traditional: true,
"fnServerParams": function (aoData) {
aoData.push(
{ "name": "TaxInvoiceIds", "value": array }
);
},
aoColumns: [
{ sTitle: "Id", bSortable: false, bVisible: false, },
{ sTitle: "PoBox Number", bSortable: false, },
{ sTitle: "Email", bSortable: false, },
{ sTitle: "Owner", bSortable: false, },
{ sTitle: "General Tax", bSortable: false, },
{ sTitle: "Consumption Tax", bSortable: false, },
{ sTitle: "Due Amount", bSortable: false, },
{ sTitle: "Date", bSortable: false, },
{ sTitle: "Detailes", bSortable: false, },
],
});
}
但它总是显示为空。
答案 0 :(得分:1)
试试这个:
aoData.push(
{ "name": "TaxInvoiceIds[]", "value": array }
);
https://github.com/DataTables/DataTablesSrc/commit/a3f57e4
或者: http://www.justinmichaels.net/custom-serverside-filtering-with-jquery-datables-and-asp-net-mvc3(我正在使用这种方式)。