T4MVC 和区域路线

发布于 2024-09-26 04:10:24 字数 2334 浏览 3 评论 0原文

我有以下区域路由注册方法:

 /// <summary>
    /// Registers the area.
    /// </summary>
    /// <param name="context">The context.</param>
    public override void RegisterArea(AreaRegistrationContext context)
    {
        // terminal customer url
        context.MapRoute("TerminalCustomer", "Terminal/Customer/{action}/{id}", new { controller = MVCt4.TerminalArea.Customer.Name, action = MVCt4.TerminalArea.Customer.ActionNames.Index, id = string.Empty });

        // terminal inbound pattern url
        context.MapRoute("TerminalInboundPattern","Terminal/InboundPattern/{action}/{id}",new { controller = MVCt4.TerminalArea.InboundPattern.Name, action = MVCt4.TerminalArea.InboundPattern.ActionNames.Index, id = string.Empty });

        // terminal outbound pattern url
        context.MapRoute("TerminalOutboundPattern","Terminal/OutboundPattern/{action}/{id}",new { controller = MVCt4.TerminalArea.OutboundPattern.Name, action = MVCt4.TerminalArea.OutboundPattern.ActionNames.Index, id = string.Empty });

        // terminal inbound shipment url
        context.MapRoute("TerminalInboundShipment", "Terminal/InboundShipment/{action}/{id}", new { controller = MVCt4.TerminalArea.InboundShipment, action = MVCt4.TerminalArea.InboundShipment.ActionNames.Index, id = string.Empty });

        // terminal outbound shipment url
        context.MapRoute("TerminalOutboundShipment", "Terminal/OutboundShipment/{action}/{id}", new { controller = MVCt4.TerminalArea.OutboundShipment, action = MVCt4.TerminalArea.OutboundShipment.ActionNames.Index, id = string.Empty });
    }

它按原样工作正常,但是当我更改为类型安全并且没有像这样的神奇方法时:

            context.MapRoute("TerminalOutboundShipment", "Terminal/OutboundShipment/{action}/{id}", MVCt4.TerminalArea.OutboundPattern.Index(), new {id = String.Empty});

我收到运行时错误?我在 global.asax 文件中有这段代码,它工作正常:

   static public void RegisterRoutes(RouteCollection routes)
    {
        // do not allow any body access our our resources
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("favicon.ico");

        // home url ok
        routes.MapRoute("Default", "Home/{action}/{id}", MVCt4.Home.Index(), new {id = String.Empty});

}

在它不起作用的区域中,将主要的全局 asa 工作正常吗?

I have the following area route registration method:

 /// <summary>
    /// Registers the area.
    /// </summary>
    /// <param name="context">The context.</param>
    public override void RegisterArea(AreaRegistrationContext context)
    {
        // terminal customer url
        context.MapRoute("TerminalCustomer", "Terminal/Customer/{action}/{id}", new { controller = MVCt4.TerminalArea.Customer.Name, action = MVCt4.TerminalArea.Customer.ActionNames.Index, id = string.Empty });

        // terminal inbound pattern url
        context.MapRoute("TerminalInboundPattern","Terminal/InboundPattern/{action}/{id}",new { controller = MVCt4.TerminalArea.InboundPattern.Name, action = MVCt4.TerminalArea.InboundPattern.ActionNames.Index, id = string.Empty });

        // terminal outbound pattern url
        context.MapRoute("TerminalOutboundPattern","Terminal/OutboundPattern/{action}/{id}",new { controller = MVCt4.TerminalArea.OutboundPattern.Name, action = MVCt4.TerminalArea.OutboundPattern.ActionNames.Index, id = string.Empty });

        // terminal inbound shipment url
        context.MapRoute("TerminalInboundShipment", "Terminal/InboundShipment/{action}/{id}", new { controller = MVCt4.TerminalArea.InboundShipment, action = MVCt4.TerminalArea.InboundShipment.ActionNames.Index, id = string.Empty });

        // terminal outbound shipment url
        context.MapRoute("TerminalOutboundShipment", "Terminal/OutboundShipment/{action}/{id}", new { controller = MVCt4.TerminalArea.OutboundShipment, action = MVCt4.TerminalArea.OutboundShipment.ActionNames.Index, id = string.Empty });
    }

It works fine as is, but when I change to the typesafe and no magic way of like this:

            context.MapRoute("TerminalOutboundShipment", "Terminal/OutboundShipment/{action}/{id}", MVCt4.TerminalArea.OutboundPattern.Index(), new {id = String.Empty});

I get a runtime error? I have this code in the global.asax file and it works fine:

   static public void RegisterRoutes(RouteCollection routes)
    {
        // do not allow any body access our our resources
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("favicon.ico");

        // home url ok
        routes.MapRoute("Default", "Home/{action}/{id}", MVCt4.Home.Index(), new {id = String.Empty});

}

In the areas it does not work put the main global asa it works fine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总攻大人 2024-10-03 04:10:24

我在 code plex 网站上找到了有关如何使用 t4mvc 的示例。

codeplex

I found a example on how to use the t4mvc on the code plex site.

codeplex

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文