【问题标题】:ASP.Net MVC MapRoute problemASP.Net MVC MapRoute 问题
【发布时间】:2009-03-31 13:00:08
【问题描述】:

SO 处理 MapRoute 问题似乎有很多问题。我已经阅读了其中的一堆,但我看不出我在实现中做错了什么。我设置了以下路线:

routes.MapRoute( _
    "FilesDisplay", _
    "{controller}/{action}/{year}/{month}", _
    New With {.controller = "Files", .action = "Display", .year = "", .month = ""})

routes.MapRoute( _
    "Default", _
    "{controller}/{action}", _
    New With {.controller = "Files", .action = "Index"})

以及以下RouteLink:

<%=Html.RouteLink("Show", "FilesDisplay", New With {.year = 2008, .month = 5})%>

但是,“Show”的结果 URL 是 /Files/Index/2008/5。为什么它选择 Index 操作而不是 Display 操作?

编辑: 顺便说一句,我将第二条路由更改为 .action = "Display" 只是为了查看是否可以更改 URL,它 仍然 解析为 /Files /索引/2008/5。

编辑2:我也试过了:

<%=Html.ActionLink("Show", "Display", "Files", New With {.year = 2008, .month = 5}, Nothing)%>

但这也解析为 /Files/Index/2008/5。为什么无论我为某个操作指定什么,它都默认为索引?

【问题讨论】:

  • 您在哪个版本的 ASP.NET MVC 上运行? RouteLinks 存在问题,您必须在其中一个版本中明确声明控制器和操作。
  • 我相信这是 RC1(我在哪里可以确认?)。
  • 我认为它显示在控制面板下的程序列表中。我认为您不能安装多个版本。
  • 它读作“Microsoft ASP.NET MVC RC”,所以我假设是 RC1。
  • 你运行的是什么版本的 IIS?

标签: asp.net-mvc model-view-controller url-routing


【解决方案1】:

升级到 MVC RC 1.0 似乎修复了 ActionLink,但没有修复 RouteLink。因此,我正在推进 ActionLink。我很想知道为什么 RouteLink 不想工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2011-07-22
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多