1

I have a cshtml controller with roughly the following logic:

public class MyController
{
    public async Task<ActionResult> Index(string query){
         // do something with query and put result in 'myModel'
         return View(await myModel.ToListAsync());
    }
}

This works perfectly when I call the action directly.

Now I want a dashboard, which calls this controller action 3 times, each with different query parameters, approximately like this:

@Html.Action("Index", "myControllerName", new { query = "foo" })
@Html.Action("Index", "myControllerName", new { query = "bar" })
@Html.Action("Index", "myControllerName", new { query = "baz" })

The code throws an exception on the first @Html line though:

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code

Additional information: [translated: error while executing] handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

Based on this question Error executing child request for handler in view I built a second method returning a partial view, and I checked if there was a [HttpGet] to remove (there wasn't). Neither works.

edit building a partial view, which is not async, does work, based on pressing continue after the exception and Googling the error, and finding this question: Async PartialView causes "HttpServerUtility.Execute blocked..." exception . Not happy with the synchronous solution though, and still working on a viable solution

Community
  • 1
  • 1
Daniël Camps
  • 1,737
  • 1
  • 22
  • 33

1 Answers1

1

As you already found out, async child actions are not supported in ASP.NET MVC 5. Support of async actions was introduced in ASP.NET Core MVC 6.

You can execute async code in your action with AyncPump from this article, but the action method must still be synchronous.

Andrii Litvinov
  • 12,402
  • 3
  • 52
  • 59