簡體   English   中英

向ASP.NET MVC 5.0控制器方法添加參數導致JQuery數據表Ajax調用掛起

[英]Adding arguments to ASP.NET MVC 5.0 Controller Method Causes JQuery Datatable Ajax Call to Hang

與標題中的內容完全相同。 由於某種原因,將我的控制器方法更改為接受參數會導致我對此方法的DataTable ajax調用失敗。

功能簽名

[AcceptVerbs("POST")]
public JsonResult LoadPayoffAgingGrid(/*string SearchText, DateTime StartDate, DateTime EndDate*/)

DataTable調用:

function LoadPayoffAgingReportGrid() {

    var wsUrl = '@Url.Action("LoadPayoffAgingGrid", "Report")';
    var dtStart = $('#dtStart').val();
    var dtEnd = $('#dtEnd').val();
    var sSearch = $('.dataTables_filter input').val();

    oTableLoansView = $('#PayoffAginggridtable').dataTable({
        "bServerSide": true,
        "sAjaxSource": wsUrl,
        "iDisplayLength": 50,

        "bProcessing": true,
        "bDestroy": true,
        "sDom": sDomStandard,
        "bJQueryUI": true,
        "error": function (jqXHR, textStatus, errorThrown) {
            alert(errorThrown);
        },
        "sServerMethod": "POST",
        "sPaginationType": "full_numbers",
        "fnServerParams": function (aoData) {
            aoData.push({ "name": "sDateStart", "value": dtStart });
            aoData.push({ "name": "sDateEnd", "value": dtEnd });
            //aoData.push({ "name": "sSearch", "value": sSearch });
        },
        "bAutoWidth": false,
        "aoColumns": [
                { "sName": "BorrName", "bSortable": true, "sClass": "alignleft hidden-xs" },
                { "sName": "LoanNumber", "bSortable": true, "sClass": "alignleft" },
                { "sName": "SubdivName", "bSortable": true, "sClass": "alignleft hidden-xs" },
                { "sName": "LotNum", "bSortable": true, "sClass": "pointer hidden-xs" },
                { "sName": "OpenDtAge", "bSortable": true, "sClass": "alignright" },
                { "sName": "AgeGroup", "bSortable": true, "sClass": "alignright hidden-xs" },
                { "sName": "PaidOffDt", "bSortable": true, "sClass": "alignright" },
                { "sName": "CommitmentAmt", "bSortable": true, "sClass": "alignright" },

        ],
        "aaSorting": [[1, 'asc']]
    });

}

誰能解釋導致MVC和Jquery數據表如此交互的原因? 我以為這是AJAX的一個方面,我不太了解。

如果添加非空參數,則需要在請求中包含它們

DateTime StartDateDateTime EndDate是必需的,並且您的請求似乎正在發送sDateStartsDateEnd ,由於參數名稱不匹配,這將引發錯誤

我發現問題在於DateTimenull之間沒有隱式轉換。 其他函數可以很好地工作,因為它們缺少DateTime類型的參數。 解決方案是使這些參數可為空,如下所示:

[AcceptVerbs("POST")]
public JsonResult LoadPayoffAgingGrid(string SearchText, DateTime? StartDate, DateTime? EndDate)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM