Friday, 15 November 2013

The following sections have been defined but have not been rendered for the layout page

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


Solution 1 : If the _Layout.cshtml has the following piece of code:
@RenderSection("scripts")

Add the following in your cshtml file:
@{
    ViewBag.Title = "My Title";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
//Add the blank section
@section scripts{
    // Add something here
}

Solution 2 : Alternative approach:
@if (IsSectionDefined("scripts"))
{
    RenderSection("scripts")
}

Solution 3: You can try another alternative approach as below:

@RenderSection("scripts", required: false)

2 comments:

  1. Where exactly do I have to put these statements? Is it in my layout view or in my controller view?

    ReplyDelete