Strongly Typed RedirectToAction
A strongly typed version of the RedirectToAction method is available that uses lambda expressions. This method can either be used to redirect to an action on the same controller or a different controller.
The strongly typed RedirectToAction is available as an extension method, meaning it is not necessary to inherit from a specific base class, but you do have to have the
MvcContrib namespace imported.
public class MyController: Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult RedirectActionOnSameController()
{
return this.RedirectToAction(c => c.Index());
}
public ActionResult RedirectActionOnAnotherController()
{
return this.RedirectToAction<AnotherController>(c => c.List());
}
}
public class AnotherController: Controller
{
public ActionResult List()
{
return View();
}
}