jbassking10
jbassking10

Reputation: 803

Use indicator for downloading file in mvc

We have a Html.BeginForm(...) with a download button in it. When the button is clicked we enable a busy indicator prior to the submit. The form posts to the controller and the controller returns a FileStreamResult with the response headers like set so the file is downloaded instead of opened or begin redirected.

HttpContext.Response.AddHeader("content-disposition", "attachment; filename=downloaded-file.pdf");

 // Return from the controller.
 return new FileStreamResult(GetTestFile(), "application/pdf");

I need a way to now disable the busy indicator once the controller returns since there is no redirection.

Upvotes: 0

Views: 232

Answers (1)

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48357

One solution that i recommend is to detect when browser receives file download

It referenced this link and this link

The ideea is following: it's sends a cookie (C# Generated) with the file (that you are downloading). Use a window.setInterval to query for the presence of a cookie at regular intervals and check its value,and, if you have that cookie you can disable busy indicator.

Upvotes: 1

Related Questions