Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return RedirectToAction in MVC using async & await

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.

like image 595
Amol Avatar asked Dec 05 '16 06:12

Amol


1 Answers

    public async Task<ActionResult> DisplayDashboard()
    {
        return await Task.Run<ActionResult>(() =>
        {
            if (true)
            {
                return RedirectToAction("Index", "Home");
            }
            else
            {
                return View("Index");
            }
        });
    }
like image 74
Bob Dust Avatar answered Oct 12 '22 12:10

Bob Dust