【问题标题】:asp.net mvc 3, need help to map the routeasp.net mvc 3,需要帮助来映射路由
【发布时间】:2012-02-01 02:05:16
【问题描述】:

这是我要映射的 URL,http://localhost/tool/votetool/123/up

        routes.MapRoute(
            "", // Route name
            "{controller}/{action}/{toolId}/{vote}", // URL with parameters
            new { controller = "Tool", action = "VoteTool", toolId = UrlParameter.Optional, vote = UrlParameter.Optional }, // Parameter defaults
            new { vote = "up|down"}
        );

在我的页面中,我使用 html.actionlink 来生成 URL。

@Html.ActionLink("ThumbUp", "VoteTool", "Tool", new { toolId = Model.Tool.Id, vote = "up" })

取而代之的是一个与此类似的 URL:http://localhost/tool/votetool/123/up

这是我得到的网址:

http://localhost:60627/Tool/VoteTool?Length=4

为什么我得到 length=4 ???

【问题讨论】:

    标签: asp.net asp.net-mvc-3 url-routing routes


    【解决方案1】:

    您正在调用 ActionLink(linkText, actionName, routeValues, htmlAttributes) 重载。

    因此,它将"Tool" 视为一组路由参数,并读取String 类(Length)的唯一属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 2011-01-31
      • 2011-08-17
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      相关资源
      最近更新 更多