Hi all,
I'm currently generating and returning a fairly large file from a controller on a button click from a view. What i'd like to be able to do is display an overlay stating "Generating File" while the file is being generated and once it's done have the overlay disappear. How would i go about doing something like this?
Here's a sample of what my controller looks like.
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();
}
Thanks in advance