0

I have a master layout and then a child layout for certain views.

In the master layout, I have:

@RenderSection("Scripts", required: false)

The child layout references the master layout itself.

But I keep getting an exception on views where there are @section Scripts

The exception is:

InvalidOperationException: The following sections have been defined but have not been rendered by the page at x

x is the child layout page.

Surely the master layout should still render the script?

Am I missing a step?

D.Man
  • 179
  • 1
  • 15

1 Answers1

0

You can refer to the official doc of Layout.A layout can optionally reference one or more sections, by calling RenderSection. Sections provide a way to organize where certain page elements should be placed.

If you use

@{
    Layout = "_Layout";
}

in your child layout,it means you can use @section Scriptsin your child layout. And if you use

@{
        Layout = "_ChildLayout";
 }

in your other views,it means the layout is _ChildLayout rather than _Layout in the views.If you want to use @section Scriptsin the views,you need to add @RenderSection("Scripts", required: false) to _ChildLayout,which is the layout of the views.

Yiyi You
  • 16,875
  • 1
  • 10
  • 22