当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > Asp.net Mvc Framework可以在Controller中使用的Url.Action方法

ASP.NET
如何在命令行下编译一个asp.net项目
ADO 与ADO.NET
当VS.NET2003遇上VS.NET2005,WebService部署何去何从
昨日关注:逐步解说: 将Web Form网页国际化
在.NET下编写中文代码程序
防止同一个程序多次运行。 [VB.NET]
Visual C#设计多功能关机程序
什么是Web Service?
实现ListView控件的行间隔颜色的优化代码
失去信心?还是再度迷惘(二):Mono only is Mono,not .NET never
在Winform中发HTTP请求(调用WebService服务)
.NET中加密和解密的实现方法 3
notNET中加密和解密的实现方法
.NET中加密和解密的实现方法2
mshtml:javascript为HTML文件中的Select添加option
VS.NET解决方案的兼容问题
关于创建快捷方式的小结
使用 GDI+ 进行双缓冲绘图
如何用DataGrid实现根据日期判断是否显示New标志
昨日关注:C-omega vs ADO.net

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 171 ::
收藏到网摘: n/a

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

使用方法:

以下为引用的内容:

public ActionResult Index() {
            ViewData[
"Message"= this.Action("home""about");
            
return View();
        }