<th>
Start date: @Html.TextBox("start_date", null, new { @class = "dateClass start", id = "StartDate" })
End date: @Html.TextBox("end_date", null, new { @class = "dateClass end", id = "EndDate", @data_toggle = "popover", @data_content = "End date should be greater than Start date. ", @title = "Attention" })
@Html.ActionLink("Export Report", "Report_CLeav", "Reports", new { @class = "IndexButton exp", @style = "text-decoration: none;color:white" })
</th>
「控制器」 公共類? ReportsController:控制器 { // GET:導出 public ActionResult索引() { return View(); }
公共無效Report_CLeav(DateTime的起始日期,日期時間END_DATE?) { 串路徑= HttpContext.Server.MapPath( 「〜/ App_Data文件/報告/ Report_LeavingCompanyHCT.xlsx」); Models.Report.Report_CompLeav reportcompleav = new Models.Report.Report_CompLeav(); var fileinfo = new FileInfo(path);
using (ExcelPackage package = new ExcelPackage(fileinfo))
{
var currentWorksheet = package.Workbook.Worksheets["HC"];
using (var excelToExport = new ExcelPackage())
{
excelToExport.Workbook.Worksheets.Add(currentWorksheet.Name, currentWorksheet);
var workBook = excelToExport.Workbook.Worksheets["HC"];
try
{
workBook = reportcompleav.exportAllEmployeeDataRRecords(workBook,start_date,end_date);
}
catch (Exception e)
{
ViewBag.IsError = true;
}
excelToExport.Save();
Stream stream = excelToExport.Stream;
var memoryStream = stream as MemoryStream;
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition",
"attachment; filename=" + fileinfo.Name);
Response.BinaryWrite(memoryStream.ToArray());
}
}
}
}
}
嘗試首先分離處理程序,比如'$(文件).off( '點擊')。在('click'' – Yang
您能不能告訴我們'.exp'元素? –
Html.ActionLink(「Export Report」,「Report_CLeav」,「Reports」,new {class =「IndexButton exp」,@style =「text-decoration:none; color:white」}) – POL11