I'm trying to have the navigation bars for my website to be a little dynamic. If a categoryId is equals to 0 I remove some buttons, else I display them all:
_Layout.cshtml:
<body>
<div class="page">
<div id="header">
<div id="logindisplay">
@Html.Partial("_LogOnPartial")
</div>
<div id="menucontainer">
@if (IsSectionDefined("Navigation"))
{
{RenderSection("Navigation", false);}
}
else
{
<p>No navigation setup!</p>
}
</div>
</div>
<div id="main">
<div id="contentwrapper">
@RenderBody()
</div>
<div id="footer">
</div>
</div>
</div>
</body>
Index.cshtml: from my HomeController
@model Project2.ViewModels.ProjectCategoryListViewModel
@{
ViewBag.Title = "Home Page";
}
@section Navigation {
@{Html.RenderAction("LayoutNav", "Home", new { CategoryId = 0 });}
}
<!-- Rest of the page's code -->
Index.cshtml: from my CategoryController
@model Project2.ViewModels.Categories.CategoryIndexViewModel
@{
ViewBag.Title = "Category Index";
}
@section Navigation {
@{Html.RenderAction("LayoutNav", "Home", new { CategoryId = Model.Category.Id });}
}
<!-- Rest of the page's code -->
I tried the exact same setup but without RenderAction and just entering html directly but I keep getting this error message:
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Navigation".
The Index actions in the Category and Home controller are straight forward ActionResults that return a View.
Any ideas what's going on there?