I have a kendo grid with custom control. Kendo Grid Export CSV is not working for me. Source code is given below. Can anyone help me.
Code running without error but CSV is not generating ( chrome).
1. kendo grid.
.Name("PayrollReport")
.ToolBar(toolbar =>
{
toolbar.Excel().HtmlAttributes(new { @class = "toolbar-field" });
toolbar.Custom()
.Text("Export To CSV")
.HtmlAttributes(new { id = "exportCSV" });
jquerry
$("#PayrollReport").on("click", "#exportCSV", function (e) {
var batchid = $("#ddlbatchidamexrpt").data("kendoDropDownList").value();
var status = $("#ddlpayrollstatus").data("kendoDropDownList").value();
//debugger;
$.ajax({
type: "POST",
url: "/Home/ExportServer",
data: JSON.stringify({ 'Batchid': batchid, 'Status': status }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
//alert("Saved Successfully");
},
failure: function (response) {
//alert("Error Occured");
}
});
e.preventDefault();
});
Home controller
[HttpPost]
public FileContentResult ExportServer(string Batchid,string Status)
{
var payrollrpt = svc.GetPayrollReport(Batchid, Status);
StringBuilder sw = new StringBuilder();
sw.AppendLine("\"CompanyID\",\"BatchID\",\"Earning5Code\",\"Earning5Amount\"\"Earning5Code\",\"Earning5Amount\"\"Earning5Code\",\"Earning5Amount\"\"Earning5Code\",\"Earning5Amount\"\"Earning5Code\",\"Earning5Amount\"");
sw.Append("\n");
foreach (var line in payrollrpt)
{
sw.AppendLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",\"{9}\",\"{10}\",\"{11}\"",
line.CompanyID,
line.BatchID,
line.Earning5CodeTERTaxable,
line.TaxableExpense,
line.Earning5CodeHotel,
line.HOTELTAX,
line.Earning5CodeAir,
line.AIRTAXB,
line.Earning5CodeOther,
line.TRNSRTAX,
line.Earning5CodeMeals,
line.Meals ));
sw.Append("\n");
}
return File(new System.Text.UTF8Encoding().GetBytes(sw.ToString()), "text/csv", "PayrollReport.csv");
}