I known There is a default _Layout.cshtml file in Asp.net MVC just like MasterPage in Asp.net Web Site. Can I define multiple layout templates in my MVC app? If so ,How to make it? Please give me some code example . Thanks.
I known There is a default _Layout.cshtml file in Asp.net MVC just like MasterPage
Share
You can create multiple Layout pages and use it in differnt views. You may mention the new layout pages inside your views by mentioning the Layout property in your views.
Create a new
Viewand name it as_AdminLayout.cshtmlunderViews/Sharedfolder. You may create your HTML markup for your master page template there. Make sure you have@RenderBody()section in your Layout page so that the content of your normal views will be replaced here when it renders.And if you want to use this Layout in a view, you can do it like this
If you want to use the new Layout for all the Views by default without explicitly mentioning like the above code, you can do it in the
Views/_ViewStart.cshtmlfile