You should be doing something like a realtime update to the client as some function finishes executing. SignalR is a good candidate to opt for.
Here is a sample dummy program which sends updates to the client. You may replace the Thread.Sleep
part with calls to your sub methods and calulate the percentage with some algorithm. This program is to give you an idea. This is not the optimal solution!
[HttpPost]
public ActionResult DoIt()
{
var context = GlobalHost.ConnectionManager.GetHubContext<IssuesHub>();
Thread.Sleep(3000);
context.Clients.All.updateProgress(new { Status = "10 %" });
Thread.Sleep(3000);
context.Clients.All.updateProgress(new { Status = "50 %" });
Thread.Sleep(3000);
context.Clients.All.updateProgress(new { Status = "60 %" });
return Json(new { Status = "100%" });
}
And in the client
$(function () {
var progress = $("#progress");
var chat = $.connection.issuesHub;
chat.client.updateProgress = function (result) {
progress.html(result.Status);
};
$.connection.hub.start();
$("#someSubmitButton").click(function(e){
e.preventDefault();
$.post("@Url.Action("DoIt","Home")");
});
});