我有这个代码......
public void ExportClientsListToExcel()
{
var grid = new System.Web.UI.WebControls.GridView();
grid.DataSource = db.GetCompleteEmpReport();
grid.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=Exported_Diners.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
我在哪里获取存储过程数据,填充网格,然后将导出到Excel.It不会给我任何错误,但没有得到所需的导出文件。我哪里出错了?
我在sw.ToString()部分获取所需数据但未导出。 我通过客户端的ajax Post调用调用该方法并拥有此代码
$("#btnExport").click(function (event) {
$.ajax({
url: 'Home/ExportClientsListToExcel',
type: 'POST',
success: function (status) {
alert();
},
});
});
alert()弹出窗口即将到来。