2

I use an ajax call in a View to load data in a PartialView without blocking the UI.

$(function() {
     $.get( '@Url.Action("MyFunction", Model)', function( data ) {
                    $("#partialContainer").html(data);
                });
            }

The Controller code is really simple, Task.Delay will be replaced with another long running call to a web service:

public ActionResult MyFunction(MyFunctionModel model)
{
      for (int i = 0; i < 4; i++) {
           Task.Delay(4000).Wait();    
      }
      return PartialView("PartialView", model);
}

What I would like to do is:

public ActionResult MyFunction(MyFunctionModel model)
{
          for (int i = 0; i < 4; i++) {
               Task.Delay(4000).Wait();    
               yield return PartialView("PartialView", model);
           }
}

but I know that I cannot use the yield operator with an ActionResult.

Edit: The final idea is to show results every time something is adding up, let's say like a flight search engine does, without waiting for the full list of elements.

Francesco De Lisi
  • 1,493
  • 8
  • 20

1 Answers1

1

You would need to implement SingalR or long polling.

If you need to update your UI in progressive way as you mentioned about flight results.

Community
  • 1
  • 1
User3250
  • 2,961
  • 5
  • 29
  • 61