Async Actions in ASP.NET MVC 4

Viewed 1071

I have a synchronous call which I need to convert to async, Im using the async/await key words but this only returns once the task has complete what I need to do is return the results to the UI one by one.

The scenario is I have a task list displayed to the user once they have authenticated however I would like the task to be loaded one at a time once they have been retrieved from the DB, here is my actionResult which puts together the search criteria to pre-filter the tasks:

public async Task<ActionResult> Index(string searchTerm = null, int page = 1)
{
    Shared.InitialiseCriteria(SearchCriteria);
    SearchCriteria.DepartmentID = DepartmentID;
    SearchCriteria.PageSize = 15;
    SearchCriteria.FreeText = searchTerm;

    var model = await DoStuff(SearchCriteria);

        if (Request.IsAjaxRequest())
        {
            return PartialView("_ConversationList", model);
        }
    return View(model);

 }

And here is the await task this calls GetConversation which essentially gets the tasks when the first task is found I need it to be loaded to the Index view :

private async Task<Result> DoStuff(CSearchCriteria SearchCriteria)
{

   return GetConversations(SearchCriteria);
}
2 Answers
Related