You can't do that. A block is technically a child action of the page. And child actions cannot be asynchronous.
If you are attempting this because you are calling an asynchronous-only API, you can run it synchronously with an AsyncHelper.
Stefan thanks for quick reply. I just want to know what could be the best strategy to perfrom async because right now i am calling Api synchoronous, due to the restriction on child actions,
We are calling blocks async but inside blocks we are right now calling API synchoronous which are causing performance issue, It there a better way to handle it ?
<script>
$('#asynchoronousBlock@(Model.BlockField)')
.load('@xxx.yyy(string.Format("/CallBlockAsync?Id={0}", Model.BlockField))',
function (respText, statusText, xhr) {
if (statusText === "error") {
LogError();
}
});
</script>
[HttpGet]
public ActionResult Index(xBlock currentBlock, xyViewModel viewModel)
{
var xxx = xxx.IndexAsync();
var yyy= yyy.Index2Async();
Task.WhenAll(xxx, yyy).Wait();
return PartialView(viewModel);
}
If you do the heavy loading in a WebAPI controller, then you can do fully asynchronous actions.
The block controller will then only render the markup and script synchronously. And you won't need to have a custom route to the block controller.
But you can't return markup from the WebAPI. So you will need to get data from the API and render it to markup on the client.
Hi Stefan thanks for your input. Are you aware of any newer EPiServer version or ASP.Net where child actions can be made asynchronous.
Hi,
I am trying to implement async call in block controller.
The method inside Index method calls the Api endpoint.
When making it async, is throws inner exception "InvalidOperationException: HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete."
It is causing a performance issue for the webiste, as we are having 4-5 blocks on page
How can I make block methods async ? I have tried a lot but still getting same error
ASP.Net version-> 5.2.7