Saturday, May 18, 2019

Layout in Asp.Net Core MVC Views

Every page on a website will have some common elements like Header, Logo, Menu, Navigation links etc. A layout helps to create a common view for these re-usable part of the page and use it in each page of the application.

A layout is also a view with .cshtml extension. The layout view defines the header, content area and the footer sections. In general re-usable content is placed in the header and footer sections, the content section varying content of the pages. The content section contains a statement @RenderBody(), which embeds the varying content of each page in the content section.

A typical layout view page looks like this.

    <html>
        <body>
            <header>
                @*Header Content*@
            </header>

            <div class="container">
                <main role="main" class="pb-3">
                    @RenderBody()
                </main>
            </div>

            <footer class="border-top footer text-muted">
                @*Footer Content*@
            </footer>
        </body>
    </html>

The default layout page for Asp.Net Core is the _Layout.cshtml view. When we create an Asp.Net Core project Visual Studio automatically creates the default layout page _Layout.cshtml, we can create additional layout pages as and when required.

Search Flipkart Products:
Flipkart.com

No comments: