What is a layout page in Razor, and what are sections?
Quick Answer
A layout is a master template (_Layout.cshtml) that holds the shared HTML shell — head, header, footer — with @RenderBody() where the page's content goes. Sections (@RenderSection("Scripts", required: false)) are named placeholders a page can fill, e.g. page-specific scripts or a sidebar.
A layout is the shared shell — _Layout.cshtml — with the head, header and footer, and @RenderBody() marks where each page's content is injected. _ViewStart wires the default layout so I don't set it in every view. Sections are named slots: the layout declares @RenderSection("Scripts", required: false) and a specific view fills it with @section Scripts { ... } — that's how a page adds its own JavaScript without every page carrying it. _ViewImports is where shared usings and tag helper registrations live.
_ViewStart.cshtmlsets the defaultLayoutfor a folder tree; a view can overrideLayout = nullor point to another.@RenderBody()— required, one per layout, renders the child view.@RenderSection("name", required: false)in the layout;@section name { ... }in the view._ViewImports.cshtmlholds shared@using,@injectand tag-helper registrations.- Layouts can nest — a section layout inside the site layout.