1

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?

1 Answer 1

3

The @ symbol is also required for RenderSection

@if(IsSectionDefined("Menu")) { @RenderSection("Menu", required: false); } else { <span>this is the default</span> } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.