原本的Url.Action方法是利用RouteCollection来实现Url的Routing的。
所以这里用一个扩展方法重现一下
using
System.Web.Routing;
static public class CUrl {
public static string Action( this Controller c, string controller, string action) {
RouteValueDictionary rvd = new RouteValueDictionary();
rvd.Add( " controller " , controller);
rvd.Add( " action " , action);
return RouteTable.Routes.GetVirtualPath(c.ControllerContext, rvd).VirtualPath;
}
}
static public class CUrl {
public static string Action( this Controller c, string controller, string action) {
RouteValueDictionary rvd = new RouteValueDictionary();
rvd.Add( " controller " , controller);
rvd.Add( " action " , action);
return RouteTable.Routes.GetVirtualPath(c.ControllerContext, rvd).VirtualPath;
}
}
使用方法:

