我目前正在從控制器生成一個相當大的文件,並從一個視圖中單擊按鈕返回。 我想要做的是在生成文件時顯示一個覆蓋層,聲明「生成文件」,一旦完成覆蓋層消失。 我將如何去做這樣的事情?在從控制器生成/返回文件的同時顯示覆蓋圖
下面是我的控制器的樣子。
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();
}
在此先感謝
我試過了,但是一旦文件被返回,頁面仍然顯示div。我試過調用$ .unblockUI();當你從服務器回來時 – 2009-12-31 17:12:50
我編輯了我的答案給出了更多的信息 – 2009-12-31 17:33:07