MVC3 - File Download - Standby Status Indicator

Ok, I did my homework and found similar topics. However, I did not find a good answer.

Using MVC3, C #, Razor View Engine.

My script is pretty simple. I have a view with a link that invokes an action on the controller. This action returns a file that was dynamically generated. The process takes from 1 to 10 seconds. During this time, I want to block the user interface and display the message "Please Waite".

My first attempt used something like this:

@Ajax.ActionLink("my test link", "myAction", new { Controller = "myController" }, new AjaxOptions { OnBegin = "ajaxStart", OnComplete = "ajaxStop" }) 

Then, the ajaxStart and ajaxStop functions used a jquery blockUI script to lock and unlock the user interface and display a "Wait" message. This worked so that it displayed a message, but the file did not load. After several studies, I found that I could not use Ajax to start a file download. If I am wrong, please enlighten me.

So, I'm back to normal ActionLink. This works in that I can upload the file. I can even catch the .click event and block the interface and show a wait message. However, how do you know when to unlock the user interface? How can I find out when the file save / open dialog opens? Perhaps if I could catch this event, I could unlock the user interface.

I saw other posts that recommend a much more complex solution, breaking the process of generating / uploading files into separate functions. I really want you to not have to save the file on the server or poll the server to see if the file is still there. It should be pretty simple.

If anyone has any ideas, let me know.

Thank you, Tony

+4
source share
1 answer

after that there was some time ago on SO: Detect when the browser receives a file download

He refers to this link: http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx

Effectively, what he does is he sends a cookie (C # Generated) with the file (which the user downloads) to the client. As soon as the client has a cookie, theoretically this happens after the file is downloaded). Javascript checks if the client has this cookie if Javascript will unlock the user interface.

+3
source

All Articles