Hello,
I'm trying to download an excel file by passing the html page, but when trying to send the html, it's passing as null.
Ajax
function exportarExcel() {
var html = $("body").html();
$.ajax({
url: location.href = '@Url.Action("ExportExcel")',
type: 'get',
data: {
Html: html,
},
});
}
Controller
[ValidateInput(false)]
[HttpGet()]
public void ExportExcel(string Html)
{
Classes.Export.ToExcelHtml(Response, Html);
}
Export
public static void ToExcelHtml(HttpResponseBase Response, string html)
{
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment;filename = Faturamento.xls");
Response.ContentEncoding = Encoding.UTF8;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
Response.Write(html);
Response.End();
}