我目前正在从视图中单击按钮从控制器生成并返回一个相当大的文件。我想做的是在生成文件时显示一个覆盖层,说明“正在生成文件”,一旦完成,覆盖层就会消失。我将如何去做这样的事情?
这是我的控制器的示例。
public ActionResult Generate(FormViewModel fvm)
{
var isValid = AreInputsValid(fvm);
if (!isValid)
{
TryUpdateModel(fvm);
return View("Index", );
}
RenderReport(new Report(fvm));
return View();
}
private void RenderReport(Models.Report report)
{
var localReport = new LocalReport { ReportPath = report.ReportPath };
var reportDataSource = new ReportDataSource(report.DataSourceName, report.Model);
localReport.DataSources.Add(reportDataSource);
var reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
var deviceInfo =
string.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat><PageWidth>11in</PageWidth><PageHeight>8.5in</PageHeight><MarginTop>0.5in</MarginTop><MarginLeft>0.25in</MarginLeft><MarginRight>0.25in</MarginRight><MarginBottom>0.5in</MarginBottom></DeviceInfo>", reportType);
Warning[] warnings;
string[] streams;
//Render the report
var renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
//Clear the response stream and write the bytes to the outputstream
//Set content-disposition to "attachment" so that user is prompted to take an action
//on the file (open or save)
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + report.ReportName + "." + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
}
提前致谢