1

拡張機能を作成しようとしています

public static ActionResult RedirectToIndexAction(this Controller controller)
        {
            return RedirectToAction("Index");
        }

のためRedirectToAction("Index")RedirectToIndexAction();

4

1 に答える 1

1

以下のようなものについてはどうですか:

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 = "" });
    }
于 2012-07-17T13:54:14.470 に答える