Asp.net Mvc Framework可以在Controller中使用的Url.Action方法

原本的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;
        }
    }


使用方法:

Code
原文地址:https://www.cnblogs.com/chsword/p/dotnetmvcframework_controlleraction.html