.net – ASP.Net MVC The following sections have been defined but have not been rendered for the layout page

asp.net-mvcnet

I have seen in a google search that some other people have had this problem… but their issue doesn't involve getting rid of default begaviour.

ok… I am useing ASP.Net MVC4. I can't stand it, but you know how it is these days, we all end up working with technology we can't stand from time to time.

in my _layout.cshtml file, I have got rid of the following lines.

    @RenderSection("featured",false)
    @RenderBody()
    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts",false)

When I run my application, I get the following error :

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout1.cshtml": "featured"

If I put the lines back in, I get the junk from the standard ASP.NET HelloWorld template… Do I need to remove or modify something else?

Best Answer

I guess your view contains "@section featured", which means it tries to output something which it identifies as "featured". Where the output actually ends up, you can specify by RenderSection in your Layout.

So if you don't do a RenderSection, ASP.NET doesn't know where to put the contents that view tries to output. Hence the error.

So your solution is probably to also get rid of the "@section featured" block.