ASP.NET MVC seems to be encouraging me to use hard-coded strings to refer to controllers and actions.
For example, in a controller:
return RedirectT
Not sure if somebody already added an extension method to one of the ASP.NET MVC related projects but here's a piece of code that you can use to create your own extension method:
public RedirectToRouteResult RedirectToAction(Expression> action, RouteValueDictionary routeValues) where TController : Controller
{
RouteValueDictionary rv = Microsoft.Web.Mvc.Internal.ExpressionHelper.GetRouteValuesFromExpression(action);
return RedirectToAction((string)rv["Action"], (string)rv["Controller"], routeValues ?? new RouteValueDictionary());
}
public ActionResult Index()
{
return RedirectToAction(x => x.Index(), null);
}
There's no parameters merging logic, so you'll have to add it by your own.
UPDATE: @mccow002 added a similar solution a few seconds before me, so I think his solution should be accepted.