HtmlHelper ActionLink 省略区域 (asp.net mvc 4)

发布于 2024-12-29 15:12:34 字数 342 浏览 1 评论 0原文

我在生成链接时遇到问题 我有一个名为“Administration”的区域,它还有一个 HomeController 作为根, 在母版页中

<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("Admin", "Index", "Home", new {area = "Administration"})</li>

我也继承了From Route,方法GetVirtualPath接受参数值 它省略了区域键,仅传递控制器和操作。

我哪里做错了?

I have problem with generation of links
I have an Area named "Administration", it also has a HomeController as a root,
In the masterpage

<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("Admin", "Index", "Home", new {area = "Administration"})</li>

Also I inherited From Route, and the method GetVirtualPath accepts the parameter values
which omits area key, and passes only controller and action.

Where did I go wrong?

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

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

发布评论

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

评论(3

情痴 2025-01-05 15:12:34

您使用了不正确的过载。您应该使用 LinkExtensions.ActionLink 方法(HtmlHelper、String、String、String、Object、 Object) (注意最后的最后一个参数)

@Html.ActionLink("Admin", "Index", "Home", new {area = "Administration"}, null)

You use incorrect overload. You should be using LinkExtensions.ActionLink Method (HtmlHelper, String, String, String, Object, Object) (note the last parameter at the end)

@Html.ActionLink("Admin", "Index", "Home", new {area = "Administration"}, null)
痴意少年 2025-01-05 15:12:34
<li>@Html.ActionLink("Home", "Index", "Home", new {area = ""}, null)</li>
<li>@Html.ActionLink("Admin", "Index", "Home", new {area = "Administration"}, null)</li>
<li>@Html.ActionLink("Home", "Index", "Home", new {area = ""}, null)</li>
<li>@Html.ActionLink("Admin", "Index", "Home", new {area = "Administration"}, null)</li>
话少情深 2025-01-05 15:12:34

问题解决了,并且出现在 DataTokens 中。我仅为区域定义区域,而不为根中的控制器定义区域。
现在可以了。谢谢!

The problem solved, and was in DataTokens. I was defining area only for areas, but not for controllers in the root.
Now it works. Thanks!

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