拡張機能を作成しようとしています
public static ActionResult RedirectToIndexAction(this Controller controller)
{
return RedirectToAction("Index");
}
のためRedirectToAction("Index")
にRedirectToIndexAction();
拡張機能を作成しようとしています
public static ActionResult RedirectToIndexAction(this Controller controller)
{
return RedirectToAction("Index");
}
のためRedirectToAction("Index")
にRedirectToIndexAction();
以下のようなものについてはどうですか:
public static RedirectToRouteResult RedirectToAction<TController>(this Controller controller, Expression<Action<TController>> action, object routeValues) where TController : Controller
{
RouteValueDictionary routeValuesFromExpression = ExpressionHelper.GetRouteValuesFromExpression(action);
var routeValueDictionary = new RouteValueDictionary(routeValues);
foreach (KeyValuePair<string, object> keyValuePair in routeValueDictionary)
{
routeValuesFromExpression.Add(keyValuePair.Key, keyValuePair.Value);
}
return new RedirectToRouteResult(routeValuesFromExpression);
}
private RedirectToRouteResult RedirectToIndex()
{
return this.RedirectToAction<MyController>(c => c.Index(), new { Area = "" });
}