GetVirtualPath returns the first route

There was 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.Optional } // Parameter defaults ); 

Site structure:
Controllers
-> MyHome
-> AuthorController
-> ArticleController
-> Views
-> Articles
---> Index.aspx
-> Author
-> Index.aspx

But when I call

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

on the page / MyHome / Article, it always returns the first routes (MyHome / Author)

Ay idean, what am I doing wrong?

+4
source share
1 answer

By default, it returns the first route. You must specify the name of the route when receiving the virtual path. http://msdn.microsoft.com/en-us/library/cc680260.ASPX

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

Source: https://habr.com/ru/post/1334805/


All Articles