【问题标题】:Issues in MVC 2 Routing controller Index PageMVC 2 路由控制器索引页面中的问题
【发布时间】:2015-02-25 09:57:04
【问题描述】:

我创建了一个名为 Consultants 的新控制器。然后我创建动作方法 Index()..

我给路线如下,

routes.MapRouteLowercase(
            "consultants",
            "consultants/index",
            new { controller = "Consultants", action = "Index" }
            );

在看来,ActionLink方法是,

<%: Html.ActionLink("Consultant Home", "Index", "Consultants", null, new { title = "Back home" })%>

但它不是路由。它显示Resource cannot be find

请纠正我的问题...

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-2 routing


    【解决方案1】:

    您似乎创建了一个名为MapRouteLowercase 的自定义RouteCollectionExtensions(或者至少我不熟悉它)。我会通过更改您的路线来测试它以确保它按预期工作:

    routes.MapRoute(
        "consultants",
        "consultants/index",
        new { controller = "Consultants", action = "Index" }
    );
    

    否则,您可能有另一个路由映射导致问题,因此请确保路​​由配置位于路由的最顶部。顺序在路由引擎在搜索模式时如何确定正确的 url 方面起着重要作用。所以从具体到一般的顺序。

    例如,如果你做了这样的事情,它会导致你当前的路线出现问题:

    routes.MapRoute(
        "dateRoute",
        "consultants/{date}",
        new { controller = "Consultants", action = "Dates", date = UrlParameter.Optional }
    );
    

    【讨论】:

      猜你喜欢
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 1970-01-01
      • 2011-07-05
      • 2011-03-15
      • 1970-01-01
      相关资源
      最近更新 更多