0
Hello,
I am trying to download an excel file by passing the html of the page, but when trying to send the html, it is 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();
}
show your
Classes.Export.ToExcelHtml()
– Leandro Angelo
And via GET will be complicated...
– Leandro Angelo