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

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

点击次数:32 次 发布日期:2008-11-21 22:14:58 作者:源代码网
源代码网推荐

源代码网整理以下原本的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();
        }

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华