Search⌘ K
AI Features

Using Shared Layouts with Razor Pages

Explore the use of shared layouts in ASP.NET Core Razor Pages to manage common HTML markup efficiently. Learn to create _Layout.cshtml and _ViewStart.cshtml files, dynamically set page titles with ViewData, and organize reusable page components that enhance maintainability across multiple pages.

Most websites have more than one page. If every page had to contain all of the current boilerplate markup in index.cshtml, that would become a pain to manage. So, ASP.NET Core has a feature named layouts.

Method to use layouts

To use layouts, we must create a Razor file to define the default layout for all Razor Pages (and all MVC views) and store it in a Shared folder to easily find it by convention. The name of this file can be anything because we will specify it, but _Layout.cshtml is good practice. We must also ...