gpt4 book ai didi

asp.net-mvc-3 - 在区域注册中注册路线

转载 作者:行者123 更新时间:2023-12-02 12:23:23 25 4
gpt4 key购买 nike

我所在的区域有两条路线,一条是自定义路线,一条是默认后备路线,请参见下文

        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/MapRoute 添加两条路线时,最后一条路线不起作用,但是当我在最后一条路线上使用 context.MapRoute 时,它​​可以工作,但我的自定义 route 的 GetVirtualPath 不用于操作链接。我以为 MapRoute 只是 context.Routes.Add 的扩展?调试路由的最佳方法是什么?我用过Phil Haacks路由调试,但它不适用于我的自定义路由,还有其他方法来调试路由吗?

我真的需要一些帮助。我在仪表板区域中的路线注册如下所示 -

        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 是一个自定义路由,您可以在此处找到代码 http://bit.ly/er6HPn通过此路由事件,像这样的链接效果很好 Html.ActionLink("Manage Roles", "manageroles", "account") 但是当我有一个应该与我的自定义路由一起使用的链接时,就像这样 Html.ActionLink(page.MetaData.名称、“编辑”、“页面”、new { document = page },null) 结果是 http://stormbreaker.local/dashboard/pages/edit?document=Stormbreaker.Example.Models.Page ,这意味着我的 PageRoute 中的 GetVirtualPath 从未使用过。谁能向我解释一下方法以及如何解决这个问题?

最佳答案

解决了,如果在RouteCollection对象中注册自定义RouteBase实例,IRouteWithArea接口(interface)允许您将该 RouteBase 实例与一个区域关联起来

关于asp.net-mvc-3 - 在区域注册中注册路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4809378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com