C# DataTables.net导出按钮未生成Excel文件

C# DataTables.net导出按钮未生成Excel文件,c#,jquery,datatables-1.10,C#,Jquery,Datatables 1.10,当我点击Datatables.net的Export按钮时,出现以下错误 下面是我的代码 $.ajax({ type: "POST", url: uri, data: JSON.stringify(args), contentType: "application/json;charset=utf-8", success: function (data, status, xhr) { //alert(&

当我点击Datatables.net的Export按钮时,出现以下错误

下面是我的代码

 $.ajax({
    type: "POST",
    url: uri,
    data: JSON.stringify(args),
    contentType: "application/json;charset=utf-8",
    success: function (data, status, xhr) {
        //alert("The result is : " + data);            
        if (!data.d) {
            $("#gvCurr").DataTable();
        }
        else {
            $("#gvCurr").DataTable({
                "aaData": JSON.parse(data.d),
                "bDestroy": true,
                dom: 'Bfrtip',
                deferRender: true,
                "bLengthChange": false,
                "bPaginate": false,                    
                buttons: [
                    {
                        extend: 'excel',
                        text: '<i class="fas fa-file-excel"></i> Export',
                        className: "btn btn-primary",
                        filename: 'DomesticInvoiceReport - ' + moment().format("DD-MMM-YYYY"),                            
                    }
                ],                    
                "columns": [                        
                    { "data": "ProjectNo" },                        
                    { "data": "CountryName" },                        
                    { "data": "StateName" },                        
                    { "data": "SectorName" },
                    { "data": "CoOrdName" },
                    { "data": "Curr1" },

                    { "data": "InvoiceNo_1" },
                    { "data": "InvoiceDate_1" },
                    { "data": "Month_1" },
                    { "data": "Year_1" },                        


                    { "data": "TotalFee_1" },
                    { "data": "EscalationAmt_1" },
                    { "data": "CurrentOPEAmt_1" },
                    { "data": "CGSTPerc" },
                    { "data": "SGSTPerc" },
                    { "data": "TotalTaxPerc_1" },
                    { "data": "TotalTaxAmt_1" },
                    { "data": "CurrentInvoiceAmt_1" },                        
                    {
                        mRender: function (data, type, row) {
                            if (row.IsWithheld_1 == "" || row.IsWithheld_1 == 0)
                                return 'No';
                        }
                    },
                    { "data": "WithheldAmt_1" },
                    { "data": "BalanceInHandUptoThisInv_1" }
                    
                ],
                "order": [[0, "asc"]]
            });
        }
        $("#entry").hide();
        $("#list").show();
    },
    error: function (xhr) {
        alert(xhr.responseText);
    }
});
$.ajax({
类型:“POST”,
url:uri,
数据:JSON.stringify(args),
contentType:“应用程序/json;字符集=utf-8”,
成功:功能(数据、状态、xhr){
//警报(“结果为:“+数据”);
如果(!data.d){
$(“#gvCurr”).DataTable();
}
否则{
$(“#gvCurr”).DataTable({
“aaData”:JSON.parse(data.d),
是的,
dom:'Bfrtip',
是的,
“bLengthChange”:false,
“bPaginate”:错误,
按钮:[
{
扩展:“excel”,
文本:“导出”,
类名:“btn btn主节点”,
文件名:'domesticenvoicereport-'+moment().format(“DD-MMM-YYYY”),
}
],                    
“列”:[
{“数据”:“项目编号”},
{“数据”:“CountryName”},
{“数据”:“StateName”},
{“数据”:“扇区名称”},
{“数据”:“坐标名”},
{“数据”:“Curr1”},
{“数据”:“发票编号1”},
{“数据”:“发票日期1”},
{“数据”:“第1个月”},
{“数据”:“第1年”},
{“数据”:“TotalFee_1”},
{“数据”:“升级1”},
{“数据”:“CurrentOpeMat_1”},
{“数据”:“CGSTPerc”},
{“数据”:“SGSTPerc”},
{“数据”:“TotalTaxPerc_1”},
{“数据”:“TotalTaxAmt_1”},
{“数据”:“CurrentInvoiceAmt_1”},
{
mRender:函数(数据、类型、行){
如果(row.ispreserved_1==“”| | row.ispreserved_1==0)
返回“否”;
}
},
{“数据”:“WithheldAmt_1”},
{“数据”:“与此投资组合的余额”}
],
“订单”:[[0,“asc”]]
});
}
$(“#条目”).hide();
$(“#列表”).show();
},
错误:函数(xhr){
警报(xhr.responseText);
}
});
如果您看到int代码,如果我注释掉{“data”:“Year_1”}之后的列,它将生成excel文件,如果我包含该列之后的列,它将给出所附图像中显示的错误。因此,这不是错误代码或js文件顺序错误的问题

我已将这些设置包括在web.config中

<httpRuntime targetFramework="4.7.2" maxRequestLength="2147483647" requestLengthDiskThreshold="2097152" executionTimeout="240" />    

<jsonSerialization maxJsonLength="2147483644" />

它在检索时正确显示记录。在导出时,它给出了一个错误。我不知道我错过了什么


我相信您有这个问题:

{
  mRender: function (data, type, row) {
     if (row.IsWithheld_1 == "" || row.IsWithheld_1 == 0)
         return 'No';
     }
},
  • 渲染回调应用于列定义,它们不能单独存在
  • 您必须返回一个值,如果您返回
    undefined
    ,您将得到“trim不是函数”
  • 正确的方法是

    { 
      data: "IsWithheld_1",
      render: function(data, type, row) {
        return (data === '' || data == 0) ? 'No' : ''
      }
    }
    

    对这就是问题所在。我改变了它,它成功了。