I want to call async method inside the ActionResult. This is how my code looks like

public HomeController :  GlassController
     public override Task<ActionResult> Index()
         vm.parkData=await _parkService.GetSpots(siteId);

Since GetSpots is an async method so I have added the await operator and I change ActionReult from public override ActionResult Index() to public override async Task<ActionResult> Index() to support the async method

But I am getting an error

'HomeController.Index()': return type must be 'ActionResult' to match overridden member 'SitecoreController.Index()'

Since my HomeController is inheriting GlassController and GlassController is inheriting SitecoreContoller. The SitecoreController does not have any async index method so I am getting the error.

Is there any way I can call the GetSports async method inside the index Action Index() method

Any help or suggestions would be appreciated

Thanks in advance


Sitecore does not support Async controller rendering. but from the Sitecore 8.2 it supports async MVC controllers.

If you want to use async actions, you need to use it outside of Sitecore contexts by indirectly invoked controllers via non-Sitecore routes or Html.RenderAction() on a Sitecore rendering. one other option is to use the AJAX base on your requirements.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.