Defining a shared layout

To use layouts, we must next create a Razor .cshtml file to define the default layout for all Razor Pages (and all MVC views). The name of this file can be anything, but _Layout.cshtml is good practice, so that is the name that you previously set in the _ViewStart.cshtml file.

In Visual Studio 2017, in the Pages folder, add a new MVC View Layout Page item.

In Visual Studio Code, in the Pages folder, create a file named _Layout.cshtml.

In both Visual Studio 2017 and Visual Studio Code, modify the content of _Layout.cshtml, as shown in the following markup (it is similar to index.cshtml, so you can copy and paste it from there):

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content= ...

Get C# 7.1 and .NET Core 2.0 – Modern Cross-Platform Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.