I want to return an action using Async and await functionality in dot net 4.5. I have used the following code.
public async Task<ActionResult> DisplayDashboard()
{
await Task.Run(() =>
{
if (true)
{
return RedirectToAction("Index", "Home");
}
else
{
return RedirectToAction("Error", "Home");
}
});
}
Its giving following error, "Cannot convert lambda expression to delegate type 'System.Action' because some of the return types in the block are not implicitly convertible to the delegate return type".
Can anybody please suggest me how to perform RedirectToAction using Task.
public async Task<ActionResult> DisplayDashboard()
{
return await Task.Run<ActionResult>(() =>
{
if (true)
{
return RedirectToAction("Index", "Home");
}
else
{
return View("Index");
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With