首页 / 网页编程 / ASP.NET / Asp.net Mvc Framework可以在Controller中使用的Url.Action方法
Asp.net Mvc Framework可以在Controller中使用的Url.Action方法2010-03-02重典原本的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;
}
}使用方法:Codepublic ActionResult Index() {
ViewData["Message"] = this.Action("home", "about");
return View();
}