Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 654
Simon_Weaver Avatar asked Mar 11 '11 06:03

Simon_Weaver


1 Answers

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 = "" })
like image 102
Darin Dimitrov Avatar answered Oct 23 '22 09:10

Darin Dimitrov