Shared Layout page
Create a
Sharedfolder underViewsfolder. (Views (.cshtml file) created under any other specific folder like 'Product' (Product\Index.cshtml) would be used by Product controller to return this view by default per MVCs convention over configuration approach. Hence its important to create shared layouts underSharedfolder).Create a layout template file e.g.
MyLayout.cshtmlAdd the common HTML content in the above file
Any content that needs to filled up by the page specific views would be rendered inside the
@renderBody()or@renderSection("titleSection").
@{
Layout = null
}
<html>
<meta name="viewport" content="width=device-width" />
<title> @renderSection("titleSection")
<html>
<body>
<div>
<div>
@renderSection("topNavBar")
</div>
<div class="col-3">
@renderSection("sidemenu")
</div>
<div>
@renderBody()
</body>With
@renderBody, anything thats in the view would be renderedAs a good practice, use
@renderSectioninstead of@renderBodyIn the View's cshtml file, specify that its going to use a shared template with below code:
Product\Index.cshtml
Last updated
Was this helpful?