public ActionResult ExportToExcelForTL() { // string ProjName = Session["ProjName"].ToString(); ApplyLeave applyLeaveObj = new ApplyLeave(); applyLeaveObj.ExportToExcelForTLList = applyLeaveObj.ExportToExcelForTL(); //Response.AddHeader("Content-Type", "application/vnd.ms-excel"); //string filename = string.Empty; //string PresentFilename = string.Empty; //filename = DateTime.Today.ToString(); //PresentFilename = filename.Substring(0,5) + " Leave Tracker Report"; //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Today.ToString().Substring(0, 5) + " Leave Tracker Report" + ""); Response.ContentType = "application/excel"; return(View(applyLeaveObj)); }