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 回答