core web application layout

Environment: core 2.1
In a web application, many pages have the same part, such as the head of the page, the title or the bottom copyright information, etc. are common to most pages. To avoid duplication of code, we can use "layout".

In the core web application, the way to use the layout:

1. Create _Layout.cshtml in the Shared folder under the Views folder, and write the public part of the Html5 code in this cshtml file. Add the code to the non-public part of the cshtml file that needs to be added:


2. Create a cshtml file in the folder associated with the controller under Views, write the different parts of the page in this cshtml file, and insert the code in the first line:

    Layout = "/Views/Shared/_Layout.cshtml";

It can be associated with _Layout.cshtml. The content of html5 in this cshtml file is automatically inserted into the @RenderBody() location in the _Layout.cshtml file.