I have one layout and one partial view that are in the shared folder. In a partial view, top menu items that are not static are presented. Therefore, I need to call an action method to get menu items from the database. To do this, I created a controller and added an action method to it.
When I try to view the page in a web browser, this error occurred:
Controller for path '/' not found or does not implement IController.
Note:
I tried the Html.RenderAction, Html.Partial methods too ... And I tried to create another view folder and create a new partial view and a new controller named with the suffix "folder name + controller".
Markup:
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
<div id="header">
@Html.Action("~/Views/Shared/_TopMenu.cshtml", "LayoutController", new {area =""}); //Here is the problem.
</div>
<div>
@RenderBody();
</div>
</body>
</html>
_TopMenu.cshtml:
@model IList<string>
@foreach (string item in Model)
{
<span>item</span>
}
LayoutController ( Controllers):
public class LayoutController : Controller
{
public ActionResult Index()
{
return View();
}
[ChildActionOnly]
[ActionName("_TopMenu")]
public ActionResult TopMenu()
{
IList<string> menuModel = GetFromDb();
return PartialView("_TopMenu", menuModel);
}
}