I use ASP.NET MVC 5 and Empty Project.
I have a Layout and a View. In the Layout I have a RenderSection() and before Rendered check that . And in the View I Add that section but Don't Render Section .
I getting This Error:
The following sections have been defined but have not been rendered for the layout page "~/Views/_Layout.cshtml": "Menu".
My Layout is:
<body> <div id="menu"> @if(IsSectionDefined("Menu")) { RenderSection("Menu", required: false); } else { <span>this is the default</span> } </div> <div id="content"> @RenderBody() </div> and my view is :
@{ ViewBag.Title = "Index"; Layout = "~/Views/_Layout.cshtml"; } <h2>Index</h2> @section Menu{ <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> </ul> } why does not work?