Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery DataTables服务器端处理和附加变量_Jquery_Ajax_Razor_Datatable_Server Side - Fatal编程技术网

JQuery DataTables服务器端处理和附加变量

JQuery DataTables服务器端处理和附加变量,jquery,ajax,razor,datatable,server-side,Jquery,Ajax,Razor,Datatable,Server Side,我一直在尝试实现一个解决方案,使用JQuery数据表和服务器端处理来显示日志。这在很大程度上是成功的。datatable声明如下所示: $('#IndexTable').dataTable({ "bServerSide": true, "oLanguage": { "sSearch": "<div class='editor-label-wide float-left'>" + "Search : " + "</d

我一直在尝试实现一个解决方案,使用JQuery数据表和服务器端处理来显示日志。这在很大程度上是成功的。datatable声明如下所示:

$('#IndexTable').dataTable({
    "bServerSide": true,
    "oLanguage": {
    "sSearch": "<div class='editor-label-wide float-left'>" +
        "Search : " +
            "</div>" +
            "<div class='editor-field float-left'>" +
                "_INPUT_" +
            "</div>" +
            "<div class='clear-left'>" +
                "<br/>" +
            "</div>",
        "sLengthMenu": "<div class='editor-label-wide float-left'>" +
                      "Display : " +
            "</div>" +
            "<div class='editor-field float-left'>" +
                "_MENU_" +
            "</div>" +
            "<div class='clear-left'>" +
                "<br/>" +
            "</div>",
        "sInfo": "<br/>Showing _START_ to _END_ of _TOTAL_ records",
},
"bDestroy": true,
"sAjaxSource": '@Url.Action("List")',
"fnServerData": function (sSource, aoData, fnCallback) {
    $.ajax({
        dataType: 'json',
        type: "POST",
        url: sSource,
        data: aoData,
        success: fnCallback,
        error: function (jqXHR, textStatus, errorThrown) { alert('Error getting logs:' + errorThrown) }
    })
},
"bPaginate": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aLengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
"aoColumnDefs": [
    { "sName": "Level", "aTargets": [0], "mDataProp": "LogLevel" },
    { "sName": "Source", "aTargets": [1], "mDataProp": "LogSource" },
    { "sName": "Date", "aTargets": [2], "mDataProp": "LogDate" },
    { "sName": "Text", "aTargets": [3], "mDataProp": "LogText" }
    ]
});
其中,
jQueryDataTableParamModel
的结构如所示

这非常适合显示、分页、搜索和排序。问题是,我在处理客户端时使用了两个下拉列表,该客户端根据两列(级别和源)过滤所有内容:

为此,我需要
列表
操作方法中的选定值。我试图通过简单地在方法中添加参数并传递它们来实现这一点

data: {
    param: aoData,
    levelId: $("#LevelList").val(),
    sourceId: $("#SourceList").val()
},
这样做是可行的,但是
jQueryDataTableParamModel
中的所有字段都是
null

我只能假设问题在于以下两者之间的差异:

data: aoData


在ajax调用中。

我通过以下操作解决了这个问题:

"ajax": {
    "url": "@Url.Action("List")",
    "type": "POST",
    'contentType': 'application/json; charset=utf-8',
    'data': function (data) {
        var tempData = {};
        tempData.pageRequest = data;

        // To addd custom parameters:
        // tempData.customParameter1 = $("#CustomParam").val()

        tempData.levelId = $("#LevelId").val();
        tempData.sourceId = $("#SourceId").val();

        return JSON.stringify(tempData);
    }
},
然后,在控制器操作中接收到以下信息:

public JsonResult List(jQueryDataTableParamModel param)
{ ... }
public JsonResult List(DataTablesPageRequest pageRequest, int levelId, int sourceId)
{ ... }
注意:我不得不将我的DataTables版本从1.9.2更新到1.10.5

public JsonResult List(DataTablesPageRequest pageRequest, int levelId, int sourceId)
{ ... }