在 ASP.NET MVC 中调用 @Html.Action(...) 时如何指定命名空间
当我尝试在 ASP.NET MVC 3 中对与当前控制器不同的命名空间中的控制器使用 Html.Action
时,出现错误:
代码:
@Html.Action("Foo", "Application", new { id = "FG2" })
错误:
路径控制器 '/rrmvc/store/checkout' 不是 发现或未实施 I控制器。
仅当控制器 ApplicationController
与当前控制器位于不同的 NAMESPACE 中时才会发生此错误,例如 StoreControllers.CheckoutController
(事实上它们也位于完全不同的区域)。
调用 Html.Action
时是否无法指定名称空间(完全限定名称空间等明显方法似乎都不起作用)?
没有可用的 lambda 方法,并且我没有运气使用Html.RenderAction
。
编辑:我认为这可能与该地区有关 - 或者这也可能是完全的转移注意力。我在不同的命名空间中有另一个控制器可以正常工作 - 所以我认为问题更复杂。如果我弄清楚了,我会回复一个答案 - 或者如果不想避免混淆,就删除这个问题!
When I try to use Html.Action
in ASP.NET MVC 3 for a controller in a different namespace from the current controller I get an error :
Code:
@Html.Action("Foo", "Application", new { id = "FG2" })
Error :
The controller for path
'/rrmvc/store/checkout' was not
found or does not implement
IController.
This error only occurs when the controller ApplicationController
is in a different NAMESPACE from the current controller such as StoreControllers.CheckoutController
(in fact they're in completely different areas too).
Is there no way to specify a namespace when calling Html.Action
(none of the obvious ways like fully qualifying the namespace seem to work)?
There are no lambda methods to use, and I had no luck using Html.RenderAction
in MVC3 RTM.
Edit : I think it might be related to the area - or perhaps this could be a complete red herring too. I have another controller in a different namespace that DOES work correctly - so I think the problem is more complicated. I'll reply with an answer if i figure it out - or just delete this question if not to avoid confusion!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果控制器位于不同的区域,您可以尝试指定此区域名称:
如果您已经在该区域内并且想要渲染位于根目录中的控制器上的操作,您可以尝试以下操作:
If the controller is in a different area you may try specifying this area name:
and if you are already inside the area and you want to render an action located on a controller in the root you could try this: