How can I specify a namespace when calling @Html.Action(…) in ASP.NET MVC

泄露秘密 提交于 2019-12-06 01:54:27

问题


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!


回答1:


If the controller is in a different area you may try specifying this area name:

@Html.Action("Foo", "Application", new { id = "FG2", area = "foo" })

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:

@Html.Action("Foo", "Application", new { id = "FG2", area = "" })


来源:https://stackoverflow.com/questions/5269744/how-can-i-specify-a-namespace-when-calling-html-action-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!