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.