在登记区登记的路线 [英] Register routes in area registration

查看:143
本文介绍了在登记区登记的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我区两条路线,一个自定义和一个默认的备用路线,见下文

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?什么是调试路线的最好方法?我已经使用菲尔Haacks 航线的调试,但它并没有与我的自定义路由工作,有没有其他的方式来调试路线?

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是一个定制的路线,你可以在这里 http://bit.ly/er6HPn 找到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/er6HPn With 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情况下,<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.iroutewitharea%28VS.100%29.aspx\">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

这篇关于在登记区登记的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆