[HttpPost]
public ActionResult Home(string from, string to) {
try {
List < ReferralModel > list = new List < ReferralModel > ();
ReferralReportBAL objReferralReportBAL = new ReferralReportBAL();
DataTable result = new DataTable();
result = objReferralReportBAL.GetAllReferral(from, to);
result.TableName = "Employee";
using(XLWorkbook wb = new XLWorkbook()) {
wb.Worksheets.Add(result);
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename= ReferralReport.xlsx");
using(MemoryStream MyMemoryStream = new MemoryStream()) {
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
} catch (Exception ex) {
throw new Exception("Post Home", ex);
}
return RedirectToAction("Home");
}