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

 

posted @ 2008-08-06 13:00 重典 阅读(633) 评论(0)  编辑 收藏 网摘 所属分类: ASP.NET MVC
发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 1261921




相关文章:

相关链接: