From the course: Learning ASP.NET Core MVC

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reuse shared HTML markup with layouts

Reuse shared HTML markup with layouts

From the course: Learning ASP.NET Core MVC

Start my 1-month free trial

Reuse shared HTML markup with layouts

- [Instructor] Navigate around the Explore California site a little bit and notice how every single page contains the same common sections such as the header, footer and even the left side bar section of the page. This is a great thing as it gives a consistent look and feel throughout the site. However, it's really painful to change each instance of those common elements across all pages in the site. Luckily ASP.NET Core MVC allows us to define special Razor pages whose sole purpose it is to define this common layout and render content from individual pages inside of this layout. These types of Razor pages are referred to as layouts and they're a great candidate to live in that shared views folder we saw ASP.NET Core MVC looking for earlier. To demonstrate how they work, let's create the new Shared folder under the Views folder. Then I'll make a copy of our index.cshtml page into this new Share folder and rename it _Layout.cshtml. Now there's nothing special about the underscore or…

Contents