After completing my research and looking through similar threads, I still haven't found a satisfactory answer to my problem.
I am currently working with MVC3, C#, and the Razor View Engine.
The situation I'm dealing with is quite straightforward. I have a view that contains a link which triggers an action on a controller. This action generates a file dynamically, a process that can take anywhere from 1 to 10 seconds. During this time, I would like to lock the UI and display a "Please Wait" message.
In my initial attempt, I tried using the following code:
@Ajax.ActionLink("my test link", "myAction", new { Controller = "myController" }, new AjaxOptions { OnBegin = "ajaxStart", OnComplete = "ajaxStop" })
The ajaxStart and ajaxStop functions were supposed to utilize the jQuery blockUI script to block and unblock the UI while displaying the "Please Wait" message. Although this method showed the message, it failed to initiate the file download. Further investigation revealed that I couldn't use Ajax to trigger a file download. If I've misunderstood this, please clarify.
Therefore, I reverted back to a regular ActionLink. It allows me to download the file successfully. I can even capture the .click event to block the UI and show the waiting message. However, the challenge lies in determining when to unblock the UI. How can I detect when the file save/open dialog box appears? If I could capture that event, I might be able to unblock the UI at the appropriate time.
I have come across other suggestions recommending a more intricate solution involving splitting the file generation/download into separate functionalities. I am keen on avoiding options that involve saving the file on the server or polling the server for completion status. The desired solution should be relatively simple.
If anybody has any insights or ideas, please share them with me.
Thank you, Tony