Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect to an action using Task in ASP.Net MVC

I have an Asynchronous controller implementation as follows,

public Task<ActionResult> UpdateUser(ProfileModel model)
{
   return Task.Factory.StartNew(showMethod).ContinueWith(
         t =>
         {
              return RedirectToAction("ViewUser","UserProfile");
         });
}

However I am unable to redirect to the action as I am keep on getting the error,

Cannot implicitly convert type, System.Threading.Taska.Task<Sytem.Web.Mvc.RedirectToRouteResult> to System.Threading.Taska.Task<Sytem.Web.Mvc.ActionResult>

However I really want to redirect to the mentioned Action, how can I do that.

like image 425
TBA Avatar asked Dec 03 '22 20:12

TBA


1 Answers

For people who come here looking for an answer, the newer versions of .NET make things simpler. Use the keyword async in the definition of the method and you can clear up the body.

public async Task<ActionResult> UpdateUser(ProfileModel model)
{
   return RedirectToAction("ViewUser","UserProfile");
}
like image 70
Miro J. Avatar answered Dec 25 '22 10:12

Miro J.