开发者

GetVirtualPath returns the first route

开发者 https://www.devze.com 2023-02-03 11:02 出处:网络
Got a strange problem with my project routes. Here are my routes: // pennames routes.MapRoute( \"pennames\", // Route name

Got a strange problem with my project routes. Here are my routes:

            // pennames
        routes.MapRoute(
            "pennames", // Route name
            "MyHome/Authors/{action}/{id}", // URL with parameters
            new { controller = "Author", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

        // article
        routes.MapRoute(
            "article", // Route name
            "MyHome/Articles/{action}/{id}", // URL with parameters
            new { controller = "Article", action = "Index", id = UrlParameter.开发者_JS百科Optional } // Parameter defaults
        );

the site structure is:

Controllers

-> MyHome

--> AuthorController

--> ArticleController

->Views

--> Article

---> Index.aspx

-> Author

-> Index.aspx

But when i call

RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext..

from the /MyHome/Article page, It always return the first routes (MyHome/Author)

Ay idean what am I doing wrong?


By default it is returning first route. You should specify route name when getting virtual path. http://msdn.microsoft.com/en-us/library/cc680260.ASPX

RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext, "article", ..
0

精彩评论

暂无评论...
验证码 换一张
取 消