Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.RenderAction MVC areas routing issue

I am attempting to render a partial view within the main Shared _Layout.chtml file of my ASP.net MVC 4 project. This simple code is shown below

@{Html.RenderAction("UserMenu", "MyController");}

This all works fine when the user is within the root of the site. However, my project also includes an 'Area' called 'Customers'.

When the user navigates to anywhere within the 'Customers' area of my site an exception occurs on the line above and the debugger basically tells me it cannot find the controller

"The controller for path '/Customers/CustomersHome' was not found or does not implement IController."

The same exception occurs if I use Html.RenderPartial

Interestingly, if I swap out Html.RenderAction for Html.Action, this exception does not occur (although obviously nothing is rendered).

Does anyone know a way round this problem?

like image 268
jjc99 Avatar asked Dec 12 '22 20:12

jjc99


1 Answers

Have you tried setting the area to a null string?

@{Html.RenderAction("UserMenu", "MyController", new { area="" });}
like image 68
Slicksim Avatar answered Jan 08 '23 16:01

Slicksim