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

1

7

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!

Sagittate answered 11/3, 2011 at 6:34 Comment(0)
T
8

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 = "" })
Tot answered 11/3, 2011 at 6:50 Comment(2)
Thank you SO much. This is one of those 3 hour problems that I could have easily worked around in numerous ways - but I just couldn't let it go. This worked just great. Thanks. All this to print out the numeric size of my generated CSS in the footer of the page!Sagittate
If anyone else comes across this problem it was the second example here that worked for me - the 'Application' controller was not present in any area - and setting area="" allowed it to be foundSagittate

© 2022 - 2024 — McMap. All rights reserved.