如何引用其他区域?

发布于 2024-09-03 05:15:07 字数 130 浏览 7 评论 0原文

我的主站点中有一个名为“Account”的控制器,我想在 Asp.net MVC 2 区域中引用它的方法。

默认情况下,区域似乎只能访问该区域内的控制器,这是有道理的,但似乎没有选择引用另一个区域的控制器。

谢谢!

I have a controller called "Account" in my main site and I would like to reference a method on it from with in an Asp.net MVC 2 Area.

It seems by default that Areas only have access to the controllers within that Area which makes sense, but there doesn't seem to be an option to reference controllers from another area.

Thanks!

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

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

发布评论

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

评论(2

新雨望断虹 2024-09-10 05:15:07

这是一个演练: http://msdn.microsoft.com/en-us/ Library/ee671793.aspx

您在routeValues 参数对象中传递区域名称。

Url.Action("Index", "Home", new { area = "MyArea" })

您需要用于 Html.ActionLink 的构造函数还有一个 htmlAttributes 参数,您可以将其设置为 null。

Html.ActionLink("Link Text", "Index", "Home", new { area = "MyArea" }, null)

使用空字符串作为默认区域。

Here's a walkthrough: http://msdn.microsoft.com/en-us/library/ee671793.aspx

You pass the area name in the routeValues parameter object.

Url.Action("Index", "Home", new { area = "MyArea" })

The constructor you need to use for Html.ActionLink also has a htmlAttributes parameter, which you can set to null.

Html.ActionLink("Link Text", "Index", "Home", new { area = "MyArea" }, null)

Use an empty string for the default area.

百善笑为先 2024-09-10 05:15:07

查看此网站,看看是否它可以帮助你。基本上,在操作链接中,您需要声明要引用的区域,就像 ID 或控制器一样。

默认区域的控制器

html.actionlink("Home", "Index", New with {.area = "", .controller = "Home"})

其他区域的控制器

html.actionlink("Home", "Index", New with {.area = "someArea", .controller = "Home"})

Take a look at this site and see if it helps you out. Basically, in your action links, you need to declare the area you want to reference just like you would an ID or controller.

Controller in default area

html.actionlink("Home", "Index", New with {.area = "", .controller = "Home"})

Controller in another area

html.actionlink("Home", "Index", New with {.area = "someArea", .controller = "Home"})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文