Using a Layout Page In the previous section, you saw that including the same content in many web pages is easy. Another approach to creating a consistent look is to use a layout page. A layout page contains the structure, but not the content, of a web page. When a web page (content page) is linked to a layout page, it will be displayed according to the layout page (template). The layout page is just like a normal web page, except from a call to the @RenderBody() method where the content page will be included. Each content page must start with a Layout directive. Layout Page: <html> <body> <p>This is header text</p> @RenderBody() <p>&copy; 2012 W3Schools. All rights reserved.</p> </body> </html> Any Web Page: @{Layout="Layout.cshtml";} <h1>Welcome to W3Schools</h1> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laborisnisi ut aliquip ex ea commodo consequat. </p> D.R.Y. - Don't Repeat Yourself With two ASP.NET tools, Content Blocks and Layout Pages, you can give your web applications a consistent look. These tools also save you a lot of work, since you don't have to repeat the same information on all pages. Centralizing markup, style, and code makes web applications much more manageable and easier to maintain.
Using a Layout Page In the previous section, you saw that including the same content in many web pages is easy. Another approach to creating a consistent look is to use a layout page. A layout page contains the structure, but not the content, of a web page. When a web page (content page) is linked to a layout page, it will be displayed according to the layout page (template). The layout page is just like a normal web page, except from a call to the @RenderBody() method where the content page will be included. Each content page must start with a Layout directive. Layout Page: <html> <body> <p>This is header text</p> @RenderBody() <p>&copy; 2012 W3Schools. All rights reserved.</p> </body> </html> Any Web Page: @{Layout="Layout.cshtml";} <h1>Welcome to W3Schools</h1> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laborisnisi ut aliquip ex ea commodo consequat. </p> D.R.Y. - Don't Repeat Yourself With two ASP.NET tools, Content Blocks and Layout Pages, you can give your web applications a consistent look. These tools also save you a lot of work, since you don't have to repeat the same information on all pages. Centralizing markup, style, and code makes web applications much more manageable and easier to maintain.
asp-netw3c-schools.docx