4
Answers

Export Excel from Database in Asp.Net MVC using partial view

Photo of Nilesh Makwana

Nilesh Makwana

6y
1.6k
1
hi, 
 
i want to export(Create) and Downlod excel file from database in ASP.NET MVC  ,anddownlod button is in partial view(is in popup) but it is not working and not show any error,,iam use ExcelPackage and create two datatable and combine customize cell ,, in worksheet
 
HttpContext.Response.Clear();
HttpContext.Response.AddHeader("", "");
HttpContext.Response.Charset = System.Text.UTF8Encoding.UTF8.WebName;
HttpContext.Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
HttpContext.Response.AddHeader("content-disposition", "attachment;
filename=filename.xlsx);
HttpContext.Response.ContentType = "application/excel";
HttpContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Response.BinaryWrite(excel.GetAsByteArray());
HttpContext.Response.End();
is not working 

Answers (4)