Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Web.Mvc.ActionResult>' to 'System.Web.Mvc.ActionResult'
11,518
You need to await
the result of calling OtherController.Index();
as this method is marked as async
. Because you are awaiting that call, your FirstController.Index
method also needs to be marked as async
.
In your FirstController.Index
method you would therefore have:
return await OtherController.Index();
Related videos on Youtube
Author by
Control Freak
I like to exercise ultimate control on all things.
Updated on October 23, 2022Comments
-
Control Freak over 1 year
Error is on line #5 of the code below:
public class FirstController : Controller{ public async Task<ActionResult> Index() { OtherController OtherController = new OtherController(); return OtherController.Index(); } }
Then the
OtherController
:public class OtherController : Controller{ public async Task<ActionResult> Index() { //Tasks... //await... return View(); } }
I tried this and get the same error on line #5:
public class FirstController : Controller{ public ActionResult Index() { OtherController OtherController = new OtherController(); return OtherController.Index(); } }
How do I get this to work?
-
nick_w over 9 yearsWhat if you went
return await OtherController.Index();
instead?
-