Home" />

为什么 @Html.ActionLink("Home", "Index", "home") 会生成 Home

发布于 2025-01-01 04:49:14 字数 235 浏览 1 评论 0 原文

当我使用 Html.ActionLink 时,我发现 @Html.ActionLink("Home", "Index", "home") 生成此字符串 Home,那么为什么地址\home\index变成了\,我发现这和web.conf中设置的默认路由有关。我查看了 mvc 3 源代码,但找不到答案。谁能帮助我?谢谢。

When I use Html.ActionLink, I found that @Html.ActionLink("Home", "Index", "home") generates this string <a href="\">Home</a>, so why the address \home\index becomes \, I found this is related with default route which setted in web.conf. I have viewed the mvc 3 source code, but I can't find answer. Who can help me? Thanks.

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

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

发布评论

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

评论(2

星軌x 2025-01-08 04:49:14

这是由于默认路由造成的。如果您不指定默认操作和控制器,它将生成 /home/index 作为 url。

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { id = UrlParameter.Optional }
);

That's due to the default route. If you don't specify default action and controller it will generate /home/index as url.

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { id = UrlParameter.Optional }
);
谁的年少不轻狂 2025-01-08 04:49:14

路由是双向的:
- in:它将传入的 url 转换为控制器/操作/参数
- out:它将控制器/动作/参数转换为url

routing is bidirectional:
- in: it converts incoming urls into controller/actions/parameters
- out: it converts controller/actions/parameters into urls

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