I have an MVC4 project with language selection:
1 main part with:
Not sure if this hits the solution from a different angle to the accepted answer, but I found that one of my controllers in the Areas section was sitting in the wrong namespace. Correcting the namespace to:
Areas.{AreaName}.Controller
fixed the issue for me.
I suspect the key factor was to have all the controllers within a given area share the same namespace.
Building on this answer by George, I found in my case that I had set my controller up properly as ThingController
and I had a properly defined method on that controller Edit
.
But.. I was referencing it in my view with
<a href="/App/ThingController/Edit" />
Where I should have been just using the name without the word controller like
<a href="/App/Thing/Edit" />
In my case I had @{ Html.RenderAction("HeaderMenu", "Layout", new { Area = string.Empty }); }
in _Layout.cshtml but the LayoutController did not exist! (I had copied _Layout.cshtml from another solution but forgot to copy the controller)
In another scenario just I would like to add is In my scenario, the name space was different for controller as it was mistake of copying controller from another project.
This problem also occurs if you don't include your controller class for compile-process in the .csproj files.
<Compile Include="YOUR_CONTROLLER_PATH.cs" />
One other cause of this error: Accidental use of Html.Action in a Layout file where Html.ActionLink may have been intended. If the view referenced by the Html.Action uses the same Layout file you effectively have created an endless loop. (The layout view loads the referenced view as partial view which then loads the layout view which loads the referenced view...) If you set a breakpoint in the Layout file and single step through the Htlm.Action you will sometimes get a more helpful message about excessive stack size.