Question

I have FileResult Controller Action that can take a couple minutes to run under some circumstances. I would like to provide our users a visual indication that the Action is running, such as a message, a spinner, or a progress bar. The trouble is, I'm having a tough time figuring out how to "detect" on the front end that the Action has completed.

I have been toying with Ajax calls to the FileResult Action, but that doesn't work because Ajax can't return a file to the browser. I also looked at Asynchronous Actions and Tasks, but it looks like FileResult does not support the "await" keyword, which I think is necessary.

At this point, I don't know what to try next, and am very open to thoughts/ideas.

Edit:

I got this working as bobek suggested. Basically, I saved the PDF file to disk, and returned the file path as an ActionResult Content(fullFilePath). Then, on my page, I used something like this to display a little spinner gif while the Action executed, and then a link to the file after it completed.

var img = $("img#reportLoadingIcon");
var link = $('a#exportedFileLink');
link.hide();
img.show();

$.ajax({
    url: url,
    success: function (result) {
        link.attr({target: '_blank', href: result});
        link.show();
        img.hide();
    }
});
Was it helpful?

Solution

You could make it a regular POST action called via AJAX, and instead of returning a File you can return path to file and redirect the user to that path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top