问题描述
我在我区两条路线,一个自定义和一个默认的备用路线,见下文
I have two routes in my area, one custom and one default fallback route, see below
var dashboardRoute = new DashboardRoute(
ObjectFactory.GetInstance<PathResolver>(),
ObjectFactory.GetInstance<VirtualPathResolver>(),
null);
context.Routes.Add(dashboardRoute);
context.Routes.MapRoute(
"Dashboard_Default", // Route name
"dashboard/{controller}/{action}/{id}", // URL with parameters
new { controller = "pages", action = "index", id = UrlParameter.Optional, area = "Dashboard" } // Parameter defaults
);
当我添加使用context.Routes.Add /图路线的最后路线不工作两条路线,但是当我使用context.MapRoute最后路线它的工作原理,但在我的自定义路线GetVirtualPath不用于actionlinks。我认为,图路线只是一个扩展context.Routes.Add?什么是调试路线的最好方法?我已经使用航线的调试,但它并没有与我的自定义路由工作,有没有其他的方式来调试路线?
when I add both routes using context.Routes.Add/MapRoute the last route is not working, but when I use context.MapRoute on the last route it works but the GetVirtualPath in my custom route is not used for actionlinks. I thought that MapRoute was just an extension to context.Routes.Add? What is the best way to debug routes? I have used Phil Haacks route debug but it does not work with my custom route, is there any other way to debug routes?
我真的需要一些帮助在这里。
在我的仪表板区我的路线注册看起来像这样 -
I really need some help here.My route registrations in my dashboard area looks like this -
var dashboardRoute = new PagesRoute(
ObjectFactory.GetInstance<PathResolver>(),
ObjectFactory.GetInstance<VirtualPathResolver>(),
null);
context.Routes.Add("Dashboard", dashboardRoute);
context.MapRoute(
"Dashboard_default",
"dashboard/{controller}/{action}/{id}",
new { controller = "dashboard", action = "index", id = UrlParameter.Optional }
);
该PageRoute是一个定制的路线,你可以在这里找到code
有了这个积极的路线这样一个链接的伟大工程Html.ActionLink(管理角色,manageroles,账户),但是当我有应该像这样Html.ActionLink(page.MetaData我的自定义路线工作的一个环节。名称,编辑,网页,新文件{=页},null)的结果是<一个href=\"http://stormbreaker.local/dashboard/pages/edit?document=Stormbreaker.Example.Models.Page\">http://stormbreaker.local/dashboard/pages/edit?document=Stormbreaker.Example.Models.Page,这意味着GetVirtualPath在我PageRoute从未使用过。任何人都可以向我解释道,我怎么能解决这个问题?
The PageRoute is a custom route and you can find the code here http://bit.ly/er6HPnWith this routes active a link like this works great Html.ActionLink("Manage Roles", "manageroles", "account") but when I have a link that should work with my custom route like this Html.ActionLink(page.MetaData.Name, "edit", "pages", new { document = page },null) the result is http://stormbreaker.local/dashboard/pages/edit?document=Stormbreaker.Example.Models.Page, this means that GetVirtualPath in my PageRoute is never used. Can anyone explain to me way and how I could fix this?
推荐答案
解决了这个问题,如果你在RouteCollection对象注册自定义RouteBase情况下,IRouteWithArea界面让你RouteBase实例与一个区域相关联
Solved it, If you register a custom RouteBase instance in the RouteCollection object, IRouteWithArea interface lets you associate that RouteBase instance with an area
这篇关于在登记区登记的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!