carlg
carlg

Reputation: 1812

Jquery event that fires when MVC controller is finished

Is there a jquery event that fires when an ASP.NET MVC 3 Controller is finished with it's work?

I have a link on an MVC page that allows the user to download a file. The MVC controller returns a file. When the link is clicked, I have a jquery function that locks the screen while the file is created. The user then gets a dialogue to save the file. But when the file is actually returned to the user, I have another jquery function that I want to run that unlocks the screen.

Here is my code:

In MVC view:

@Html.ImageLink("Download as CSV", "Report", "GetCSVFile", "", Url.Content("~/Content/images/csv.png"), "Generate Report", null, null, null, true, "blockscreenfunction") 

In controller:

public ActionResult GetCSVFile ()
{
    string fullName = service.initiateCsvGeneration(1);
    string fileName = Path.GetFileName(fullName);
    return File(fullName, "text/csv", fileName);
}

So in summary, when the user starts the download, I lock the screen with the jquery blockscreenfunction function. The controller then creates the file and the user gets the file download dialogue. I have another jquery function that I use to unlock the screen. How can I execute this function after the controller returns the file?

Upvotes: 1

Views: 1143

Answers (1)

Jude Duran
Jude Duran

Reputation: 2205

You might wanna try @Ajax.ActionLink instead. It has OnComplete property where you can set that jQuery function that unlocks the screen.

@Ajax.ActionLink("Download FIle", "ActionName", "ControllerName", ... ,  new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, OnBegin = "LockScreenFunction", OnComplete = "UnlockScreenFunction", UpdateTargetId = "TargetElement" })

Upvotes: 1

Related Questions