asp.net mvc 3,需要帮助映射路线
这是我要映射的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在调用
ActionLink
的(linkText, actionName, routeValues, htmlAttributes)
重载。因此,它将
“Tool”
视为一组路由参数,并读取String
类的唯一属性(Length
)。You're calling the
(linkText, actionName, routeValues, htmlAttributes)
overload ofActionLink
.Therefore, it treats
"Tool"
as a set of route parameters and reads the only property of theString
class (Length
).