Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Async ActionResult

Vote:
 

Hi

I have this a method: public override ActionResult Index(someobject)

Which I want to turn into: public async Task Index(someobject)

However above does not work.

Anyone got an idea to how to have async actionresult methods in episerver?

#136970
Sep 18, 2015 15:54
Vote:
 

Let's say you have the following block controller:

public class MyBlockController : BlockController<MyBlock>
{
    public override ActionResult Index(MyBlock currentBlock)
    {
        ...
        return PartialView(model);
    }
}

Create new base controller:

public abstract class BaseController<TContentData> : ActionControllerBase, IRenderTemplate<TContentData>, IRenderTemplate where TContentData : IContentData
{
 
}

Your block controller should look like this:

public class MyBlockController : BaseController<MyBlock>
{
    public async Task<ActionResult> Index(MyBlock currentBlock)
    {
        ...
        await DoAwaitableOperation();
        ...
        return PartialView(model);
    }
}

Hope this helps!

#136974
Edited, Sep 18, 2015 16:54
Vote:
 

Hi Decan

Thanks for your reply., 

However I seem to have found a solution. 

#138437
Sep 22, 2015 9:01
Vote:
 

Hi Muhammad, your first try should work. This is how I have implemented async task -> 

public async Task<ActionResult> Index(ArticlePage currentPage)
{

}

I inherit PageController. It works. You have the identical code, right?

#138486
Sep 22, 2015 15:30
Vote:
 

Thanks guys

I have managed to solved it without hassle.  I used Andreas' approach which seems most easy.

#139309
Sep 29, 2015 15:46
Vote:
 
#174444
Jan 26, 2017 13:17
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.