Asp.net mvc: make RedirectToAction (string, object) in RedirectToAction <Controller> (x => x.Detail (id))
Does anyone know how to make a method (I'll put it in an extension class) that will do the same as mvc RedirectToAction, only using expressions (no magic lines).
So, instead of writing something like this:
RedirectToAction("Detail",
new RouteValueDictionary { {"messageId", messageId}});
I would do the following:
this.RedirectToAction(x => x.Detail(messageId));
I tried and did something like this, but I don't know how to add parameters:
public static RedirectToRouteResult RedirectToAction<T>(this T controller,
Expression<Action<T>> expression)
{
return RedirectToAction(
(expression.Body as MethodCallExpression).Method.Name
);
}
+3
2 answers
http://www.clariusconsulting.net/blogs/kzu/archive/2008/04/07/59274.aspx
, , HtmlHelper MVC Futures, 1.0, .
+1