0

(using ASP.NET MVC) I am working on a page that generates an excel "report" on button click. The contents of the report depend on user selections, so it may take 5 seconds to generate, or it may take 30 seconds.

I am trying to figure out how execute browser-side code once the excel file is generated and begins downloading so that I can display a loading message and give them the option to generate additional reports.

When the user clicks the generate report button I am submitting a form:

$("#genReportBtn").click(function () {
  ...processing stuff...
  $("#genContractForm").submit();       
});

Which links to a FileResult type function on the server side:

public FileResult GenReport(...Variables...)
{
    ...Generating Excel File...

    return File(output.ToArray(),
        "application/vnd.ms-excel",
        "report.xls");
}

Which starts the download.

Is there any way to detect this return browser side?

2
  • Is it the file download or server processing that is taking the longest time here? Commented Apr 1, 2014 at 0:17
  • It is the server processing that is taking a while. Once the download has started I would like the loading message to close. Commented Apr 1, 2014 at 0:54

1 Answer 1

1

You will need to look into signalR to push progress to the client or use a technique that basically polls for progress. For example, I had to upgrade a report that rendered a pdf/excel file for an individual user to render the report for a wide selection of users. I was able to dissect the processing so that if the user requested 45 user reports then I could formulate a progress indicator that would update on the client for each of the 45 reports.

This was not trival for me. I used this article by Dino Esposito as a starting point. In a nutshell, it allows the client to poll a controller method on a timer for progress using a taskID to serialize access. I had to modify the code to fit my needs but it ended up working as expected.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the help. This looks a little more complicated than I expected, but certainly seems doable.
Actually, SignalR is a tipical example of something that's easier done than said.
There is no "need" of SignalR, although it is one possible approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.