Aaron Stanley King

I solve problems -- occasionally code is involved.

Showing Progress of a ASP.NET MVC PartialView

What you’ll need for this recipe:

  1. Some long running GET that you really don’t want the rest of the page load to wait for.
  2. New ActionResult in a Controller that returns a PartialView.
  3. ViewUserControl that will display the results of your long running GET.
  4. jQuery and a javascript snippet that will go call your action and load your result.

Step 1 – Action Result

 1: public ActionResult CreateData(int item) 
 2: { 
 3: // Go to your Model/API/Service and get the long running stuff
 4: List LargeList = Model.GoGetList(item);
 6: // You can either add it to the ViewData or return it.. 
 7: // Do what you like
 8: ViewData.Add("ElementIdS", group.ElementIds); 
 10: // Go return your control.. 
 11: //it's named the same as you *.ascx file
 12: return PartialView("UserControl"); 
 13: }

Step 2 – ViewUserControl

Go create you *.ascx file.  This one could be call UserControl.ascx.  Add some HTML to render your long running piece of data.

Step 3 – jQuery


Step 4 – Hook it up and run

Run.  It works.