【问题标题】:datatable.js fnServerParams is not working with parameterized array datadatatable.js fnServerParams 不适用于参数化数组数据
【发布时间】:2015-01-19 16:09:29
【问题描述】:

我将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, },
        ],
    });

}

但它总是显示为空。

【问题讨论】:

  • 你能用请求的正文更新你的问题吗?
  • 当然...对不起我的英语不好...
  • 实际上我尝试在我的控制器操作中传递一个数组。我已经使用了 '$.makeArray' 但它不起作用。
  • 如果您将long[] TaxInvoiceIds 更改为string[] TaxInvoiceIds 甚至只是string TaxInvoiceIds,会发生什么?
  • 是的,当我将 'string[] ' 替换为 'string' 时它正在工作,但你的意思是不可能使用数组?

标签: c# jquery asp.net-mvc-3 datatables


【解决方案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(我就是这样用的)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2020-02-28
    • 2021-03-10
    • 2017-03-25
    • 1970-01-01
    相关资源
    最近更新 更多