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