Roger Lipscombe
Roger Lipscombe

Reputation: 91845

Doing something that'll take a while in ASP.NET MVC, while reporting progress to the user?

In my ASP.NET MVC application, one of my actions is going to take a while -- it kicks off a sequence of other tasks. I'd like to report progress to the user. I want to display text -- I don't want a simple progress bar or spinner.

How should I go about doing the two parts? First, how do I display progress to the user? Second, how should I implement the action so that progress is available to the user?

Upvotes: 1

Views: 228

Answers (3)

Roger Lipscombe
Roger Lipscombe

Reputation: 91845

I'm doing some playing around, and currently I've got the following in mind:

  1. In the initial controller action, start a background thread that does the actual work, return immediately.
  2. In the web page, use a timer to query a "GetProgress" action. This'll return some JSON that can be used to update the web page. I'll be using jQuery.
  3. In the GetProgress action, query the background thread for its progress.

I'll probably pass a Job ID to GetProgress, and use this to identify which background thread I'm asking about.

Upvotes: 1

Arnis Lapsa
Arnis Lapsa

Reputation: 47597

My ideas:

Create controller method, which returns JSON:

{
    "Message" : "Processing something serious",
    "Percentage" : "43"
}

Handle it through JS - put message span & bar indicator in seperated div, change it's content.

For progress bar i would use this one.

Upvotes: 2

aleemb
aleemb

Reputation: 32085

I started of writing a response but then I realized I should just redirect to the Progress Indicator AJAX pattern resource. It has a comprehensive yet concise discussion of the problems, solutions, usability considerations and other interesting details.

Upvotes: 1

Related Questions