I have just added a new Admin area to my project as its started to get quite large and I want to keep it structured.
I have a _ViewStart.cshtml view which sets a shared layout page to include a menu and a partial with some user information. As this wasn't being added on my area page, I've added the _ViewStart file to my area too.
This file sets the layout to "~/Views/Shared/_Layout.cshtml", which is outside my Admin area. However, the _Layout file includes a RenderAction() method which calls a Child action method on the controller for rendering. The problem is that the area doesn't seem to have visibility of this controller and so throws the following exception:
The controller for path '/Admin/LeadOrigin' was not found or does not implement IController.
The point where it occurred though is here:
Line 70: <div id="logindisplay"> Line 71: @{ Line 72: Html.RenderAction("UserInfo", "Account"); Line 73: } Line 74: </div>
The RenderAction() above works normally as the Account controller is within the scope of the view, whereas in the Admin area, it seems it has no scope of this controller.
Any ideas how to get round this problem?
RenderAction(HtmlHelper, String) Invokes the specified child action method and renders the result inline in the parent view. RenderAction(HtmlHelper, String, Object) Invokes the specified child action method using the specified parameters and renders the result inline in the parent view.
The difference between the two is that Html. RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount of HTML) whereas Html. Action returns a string with the result.
You can specify the area as part of the RouteValueDictionary (or just object of route values) which RenderAction takes as a third parameter in your case:
Html.RenderAction("UserInfo", "Account", new { area = "" });
This is assuming the Account controller is in the root area.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With