Shared Layout page
Create a
Shared
folder underViews
folder. (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 underShared
folder).Create a layout template file e.g.
MyLayout.cshtml
Add 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")
.
With
@renderBody
, anything thats in the view would be renderedAs a good practice, use
@renderSection
instead of@renderBody
In 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?