Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please wait page in ASP.NET MVC

A page executes a number of tasks and takes a long time to process. We want to give the user feedback as each task is completed.

In ASP.NET webforms we used Response.Flush()

What way would you a approach this in ASP.NET MVC?

like image 883
Karl Glennon Avatar asked Oct 20 '08 09:10

Karl Glennon


5 Answers

You can still use Response.Write() and Response.Flush() for whatever status you want to send down the wire. Or if you have your progress thingy in a user-control, you could do something like:

this.PartialView("Progress").ExecuteResult(this.ControllerContext);
this.Response.Flush();

from your controller while doing your lengthy operation in the controller's action method.

It's up to you to choose this or the client-side approach as mentioned in the comments here, just wanted to point out that server-side is still possible.

like image 65
liggett78 Avatar answered Nov 03 '22 16:11

liggett78


I would suggest to use AJAX for displaying progress. See links for ideas:

  • Real-Time Progress Bar With ASP.NET AJAX
  • Using jQuery Plugins with ASP.NET
  • Ajax Progress Bar Control
like image 27
Panos Avatar answered Nov 03 '22 15:11

Panos


There are two basic ways:

  1. Poll a server page that returns the status, then once the operation is done, redirects to a results page. MVC is nothing to do with this way, you'd need to use a server variable to store objects/status - this is a way that's more relevant to a standard Asp.NET application as you're (presumably) using session variables etc. anyway.

  2. AJAX call from the client to a webservice on the server. Asp.NET MVC is going to be rolling the jQuery framework in, so use that for the client call and event handling for the response. This would be more in the spirit of MVC which doesn't/shouldn't use session state etc.

like image 37
marcus.greasly Avatar answered Nov 03 '22 15:11

marcus.greasly


Me personally I would consider two optoins:

  • redirect to wait page(s), then fire actions
  • Do it ajax style
like image 28
Boris Callens Avatar answered Nov 03 '22 16:11

Boris Callens


You can make it in client side. In each step, you set some session variable with the current step. Then, You make another action in your controller say called: "GetProgress" and assign a view and URI for it.

In the action, you will check this session and return the current progress of your task. In the client side, make a timer (i.e setTimeOut) and you invoke the URI of the later controller action every specific amount of time - 1 second or so. That is it.

like image 43
mohammedn Avatar answered Nov 03 '22 16:11

mohammedn