asp.net mvc 3,需要帮助映射路线

发布于 2025-01-02 01:41:48 字数 942 浏览 4 评论 0原文

这是我要映射的 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

这是我得到的 URL:

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

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

here's the URL I want to map, 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"}
        );

in my page I use html.actionlink to generate the URL.

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

Instead getting an URL similar to this one : http://localhost/tool/votetool/123/up

here's the URL I am getting:

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

why am I getting length=4 ???

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

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

发布评论

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

评论(1

抱着落日 2025-01-09 01:41:48

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

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

You're calling the (linkText, actionName, routeValues, htmlAttributes) overload of ActionLink.

Therefore, it treats "Tool" as a set of route parameters and reads the only property of the String class (Length).

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