Ok, I've done my homework and have found similar threads. However, I haven't found a good answer.
Using MVC3, C#, Razor View Engine.
My scenario is pretty straightforward. I have a view with a link that calls an action on a controller. That action returns a file that was dynamically generated. The process takes anywhere from 1 to 10 seconds. During this time I want to lock the UI and display a "Please Waite" message.
My first attempt used something like this:
@Ajax.ActionLink("my test link", "myAction", new { Controller = "myController" }, new AjaxOptions { OnBegin = "ajaxStart", OnComplete = "ajaxStop" })
The ajaxStart and ajaxStop functions then used the jquery blockUI script to block and unblock the UI and display the "Please Wait" message. This worked in that it showed the message, but no file would download. After some more research, I found that 开发者_如何转开发I could not use Ajax to initiate a file download. If I'm wrong, please enlighten me.
So, I'm back to a normal ActionLink. This works in that I can download a file. I can even catch the .click event and block the UI and show the wait message. However, how do I know when to unblock the UI? How can I know when the file save/open dialog has opened up? Perhaps if I could catch that event I could then unblock the UI.
I have seen the other posts that recommend a much more complex solution by breaking the file generation/download into separate functionality. I very much want to avoid having to save the file on the server, or having to poll the server to see if the file is done yet. This should be fairly simple.
If anyone has any ideas, please let me know.
Thanks, Tony
there was a post awhile back on this on SO: Detect when browser receives file download
It referenced this link: http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx
Effectively what it does is it sends a cookie (C# Generated) with the file (that the user is downloading) to the client. Once the client has the cookie, theoretically this happens after the file is downloaded). Javascript will check to see if the client has that cookie, if so Javascript will unblock the UI.
精彩评论