.Net Core Layout


Main Layout

We have included styles and scripts files in Common Master Layout. You can find these files at the same path inside Pages/Layouts/ folder.

@{
  @* using this variables to load front pages assets *@
  bool isFront = ViewData["isFront"] is bool isFrontValue ? isFrontValue : false;
  ViewData["main"] = isFront ? "front-" : "";
  ViewData["frontVar"] = isFront ? "Front" : "";
  @* Compact/Fluid class *@
  ViewData["contentType"] = ViewData["container"] is string container && container == "container-xxl" ? "layout-compact" : "layout-wide";
}

@inject IHttpContextAccessor httpContextAccessor

<!DOCTYPE html>
<html lang="en" class="@(ViewData["navbarType"] is string navbarType ? navbarType : "")
@(ViewData["menuFixed"] is string menuFixed ? menuFixed : "")
@(ViewData["menuCollapsed"] is string menuCollapsed ? menuCollapsed : "")
@(ViewData["contentType"] is string contentType ? contentType : "")
@(ViewData["footerFixed"] is string footerFixed ? footerFixed : "")
@(ViewData["customizerHidden"] is string customizerHidden ? customizerHidden : "")" dir="ltr" data-skin="default" data-bs-theme="light" data-assets-path='@((httpContextAccessor.HttpContext?.Request.PathBase ?? "") + "/")' data-template='@(isFront ? "front-page" : (Convert.ToBoolean(TempData.Peek("menuHorizontal")?.ToString()) ? "horizontal-menu-template" : "vertical-menu-template"))'>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
  <meta name="robots" content="noindex, nofollow" />

  @{
    string title = ViewData["title"] as string ?? "";
    string appName = TempData.Peek("appName") as string ?? "";
  }
  <title>@title | @appName - Asp.Net Core Admin Template</title>
  <meta name="description" content="@TempData.Peek("description")" />
  <meta name="keywords" content="@TempData.Peek("keywords")" />
  <meta property="og:title" content="@TempData.Peek("ogTitle")" />
  <meta property="og:type" content="@TempData.Peek("ogType")" />
  <meta property="og:url" content="@TempData.Peek("ogUrl")" />
  <meta property="og:image" content="@TempData.Peek("ogImage")" />
  <meta property="og:description" content="@TempData.Peek("ogDescription")" />
  <meta property="og:site_name" content="@TempData.Peek("creatorName")" />
  <link rel="canonical" href="@TempData.Peek("productPage")" />

  <!-- Favicon -->
  <link rel="icon" type="image/x-icon" href="~/img/favicon/favicon.ico" />

  <!-- Core Styles -->
  @await Html.PartialAsync("Layouts/Sections/_Styles" + ViewData["frontVar"])


  <!-- Vendor Styles -->
  @RenderSection("VendorStyles", required: false)

  <!-- Page Styles -->
  @RenderSection("PageStyles", required: false)

  <!-- Include Scripts for customizer, helper, analytics, config -->
  @await Html.PartialAsync("Layouts/Sections/_ScriptsIncludes" + ViewData["frontVar"])
</head>

<body>
  <!-- Layout Content -->
  @RenderBody()
  <!--/ Layout Content -->

  <!-- Core Scripts -->
  @await Html.PartialAsync("Layouts/Sections/_Scripts" + ViewData["frontVar"])

  <!-- Vendor Scripts -->
  @RenderSection("VendorScripts", required: false)

  <script src='~/js/@ViewData["main"]main.dist.js'></script>

  <!-- Page Scripts-->
  @RenderSection("PageScripts", required: false)
</body>

</html>
Variables

Included variable file contains all the required variables through out the application.

You can find this file at Pages/Layouts/Sections/_Variables.cshtml

@{
  TempData["appName"] = "MyAdmin";
  TempData["creatorName"] = "themeSelection";
  TempData["appUrl"] = "https://themeselection.com";
  TempData["description"] = "Pro is the best bootstrap 5 dashboard for responsive web apps. Streamline your app development process with ease.";
  TempData["main"] = "main";
  TempData["keywords"] = "bootstrap, admin, dashboard, template, theme, responsive, web app, pro";
  TempData["ogTitle"] = "Bootstrap 5 Dashboard PRO by ThemeSelection";
  TempData["ogType"] = "website";
  TempData["ogUrl"] = "https://themeselection.com/item/sneat-aspnet-core-admin-template/";
  TempData["ogImage"] = "https://ts-assets.b-cdn.net/ts-assets/sneat/sneat-bootstrap-aspnet-core-admin-template/marketing/sneat-hrml-aspnet-core-razor-pages-pro-smm-banner.png";
  TempData["ogDescription"] = "Pro is the best bootstrap 5 dashboard for responsive web apps. Streamline your app development process with ease.";
  TempData["canonical"] = "https://themeselection.com/item/sneat-aspnet-core-admin-template/";

  @* Footer & Misc urls *@
  TempData["authorName"] = "ThemeSelection";
  TempData["authorUrl"] = "https://themeselection.com/";
  TempData["licenseUrl"] = "https://themeselection.com/license/";
  TempData["productPage"] = "https://themeselection.com/item/sneat-aspnet-core-admin-template/";
  TempData["livePreview"] = "https://demos.themeselection.com/sneat-aspnet-core-admin-template/html/vertical-menu-template/";
  TempData["support"] = "https://themeselection.com/support/";
  TempData["documentation"] = "https://demos.themeselection.com/sneat-bootstrap-html-admin-template/documentation";
  TempData["documentation_menu_link"] = "https://demos.themeselection.com/sneat-bootstrap-html-admin-template/documentation/net-core-introduction.html";
  TempData["adminTemplates"] = "https://themeselection.com/item/category/admin-templates/";
  TempData["bootstrapDashboard"] = "https://themeselection.com/item/category/admin-template-bootstrap/";
  TempData["twitterUrl"] = "https://x.com/Theme_Selection";
  TempData["instagramUrl"] = "https://www.instagram.com/themeselection/";
  TempData["githubFreeUrl"] = "https://github.com/themeselection";
  TempData["facebookUrl"] = "https://www.facebook.com/ThemeSelections/";
}

Main Partials

Styles

Included styles file contains all the core css, theme css, demo css and more..

You can find this file at Pages/Layouts/Sections/Styles.cshtml

<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&ampdisplay=swap" rel="stylesheet" />
<environment include="Development">
  <!-- Iconify icons -->
  <link rel="stylesheet" href="~/vendor/fonts/iconify-icons.dist.css" />
  <link rel="stylesheet" href="~/vendor/libs/pickr/pickr-themes.dist.css" />

  <!-- Core CSS -->
  <link rel="stylesheet" href="~/vendor/css/core.dist.css" />
  <link rel="stylesheet" href="~/css/demo.css" />

  <!-- `perfect-scrollbar` library required by SideNav plugin -->
  <link rel="stylesheet" href="~/vendor/libs/perfect-scrollbar/perfect-scrollbar.dist.css" />


  <!-- Application stylesheets -->
  <link rel="stylesheet" href="~/css/site.dist.css" />
</environment>

<environment exclude="Development">
  <!-- Iconify icons -->
  <link rel="stylesheet" href="~/vendor/fonts/iconify-icons.dist.css" asp-append-version="true" />
  <link rel="stylesheet" href="~/vendor/libs/pickr/pickr-themes.dist.css" asp-append-version="true" />

  <!-- Core CSS -->
  <link rel="stylesheet" href="~/vendor/css/core.dist.css" asp-append-version="true" />
  <link rel="stylesheet" href="~/css/demo.css" />

  <!-- `perfect-scrollbar` library required by SideNav plugin -->
  <link rel="stylesheet" href="~/vendor/libs/perfect-scrollbar/perfect-scrollbar.dist.css" asp-append-version="true" />


  <!-- Application stylesheets -->
  <link rel="stylesheet" href="~/css/site.dist.css" asp-append-version="true" />
</environment>
Head Scripts

This file includes helpers, customization, config js along with templateCustomizer initialization script :

You can find this file at Pages/Layouts/Sections/ScriptsIncludes.cshtml

<environment include="Development">
  @* Template helper js *@
  <script src="~/vendor/js/helpers.dist.js"></script>
  @* Template customizer js *@
  <script src="~/vendor/js/template-customizer.dist.js"></script>
  @* Config file contain global vars & default theme options, Set your preferred theme option in this file. *@
  <script src="~/js/config.dist.js"></script>
</environment>
  
<environment exclude="Development">
  <script src="~/vendor/js/helpers.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/js/template-customizer.dist.js" asp-append-version="true"></script>
  <script src="~/js/config.dist.js" asp-append-version="true"></script>
</environment>  
Scripts

This file includes main js along with template related vendor scripts :

You can find this file at Pages/Layouts/Sections/Scripts.cshtml

<environment include="Development">
  <script src="~/vendor/libs/jquery/jquery.dist.js"></script>
  <script src="~/vendor/libs/popper/popper.dist.js"></script>
  <script src="~/vendor/js/bootstrap.dist.js"></script>
  <script src="~/vendor/libs/%40algolia/autocomplete-js.dist.js"></script>

  <script src="~/vendor/libs/pickr/pickr.dist.js"></script>

  <!-- `perfect-scrollbar` library required by SideNav plugin -->
  <script src="~/vendor/libs/perfect-scrollbar/perfect-scrollbar.dist.js"></script>
  <!-- `hammer` required for swipe guesture -->
  <script src="~/vendor/libs/hammer/hammer.dist.js"></script>
  <!-- `i18n` required for translation -->
  <script src="~/vendor/libs/i18n/i18n.dist.js"></script>

  <script src="~/vendor/js/menu.dist.js"></script>
  <script src="~/js/site.dist.js"></script>
</environment>

<environment exclude="Development">
  <script src="~/vendor/libs/jquery/jquery.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/libs/popper/popper.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/js/bootstrap.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/libs/%40algolia/autocomplete-js.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/libs/pickr/pickr.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/libs/perfect-scrollbar/perfect-scrollbar.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/libs/hammer/hammer.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/libs/i18n/i18n.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/js/menu.dist.js" asp-append-version="true"></script>
  <script src="~/js/site.dist.js" asp-append-version="true"></script>
</environment>

Front Partials

Styles (Front)

Included styles file contains all the core css, theme css, demo css and more..

You can find this file at Pages/Layouts/Sections/StylesFront.cshtml

<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
<environment include="Development">
  <!-- Iconify icons -->
  <link rel="stylesheet" href="~/vendor/fonts/iconify-icons.dist.css" />
  <!-- Core CSS -->
  <link rel="stylesheet" href="~/vendor/css/core.dist.css" />
  <link rel="stylesheet" href="~/css/demo.css" />

  <link rel="stylesheet" href="~/vendor/libs/pickr/pickr-themes.dist.css" />

  <link rel="stylesheet" href="~/vendor/css/pages/front-page.dist.css" />

  <!-- Application stylesheets -->
  <link rel="stylesheet" href="~/css/site.dist.css" />
</environment>

<environment exclude="Development">
  <!-- Fonts & Flag icons -->
  <link rel="stylesheet" href="~/vendor/fonts/iconify-icons.dist.css" asp-append-version="true" />

  <!-- Core CSS -->
  <link rel="stylesheet" href="~/vendor/css/core.dist.css" asp-append-version="true" />
  <link rel="stylesheet" href="~/css/demo.css" asp-append-version="true" />
  <link rel="stylesheet" href="~/vendor/libs/pickr/pickr-themes.dist.css" asp-append-version="true" />

  <link rel="stylesheet" href="~/vendor/css/pages/front-page.dist.css" asp-append-version="true" />

  <!-- Application stylesheets -->
  <link rel="stylesheet" href="~/css/site.dist.css" asp-append-version="true" />
</environment>
Head Scripts (Front)

This file includes helpers, customization, config js along with templateCustomizer initialization script :

You can find this file at Pages/Layouts/Sections/ScriptsIncludesFront.cshtml

<environment include="Development">
  @* Template helper js *@
  <script src="~/vendor/js/helpers.dist.js"></script>
  @* Template customizer js *@
  <script src="~/vendor/js/template-customizer.dist.js"></script>
  @* Config file contain global vars & default theme options, Set your preferred theme option in this file. *@
  <script src='~/js/front-config.dist.js'></script>
  
  <script src="~/vendor/js/dropdown-hover.dist.js"></script>
  <script src="~/vendor/js/mega-dropdown.dist.js"></script>
</environment>
  
<environment exclude="Development">
  <script src="~/vendor/js/helpers.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/js/template-customizer.dist.js" asp-append-version="true"></script>
  <script src='~/js/front-config.dist.js' asp-append-version="true"></script>

  <script src="~/vendor/js/dropdown-hover.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/js/mega-dropdown.dist.js" asp-append-version="true"></script>
</environment>
Scripts (Front)

This file includes main js along with template related vendor scripts :

You can find this file at Pages/Layouts/Sections/ScriptsFront.cshtml

<environment include="Development">
  <script src="~/vendor/libs/popper/popper.dist.js"></script>
  <script src="~/vendor/js/bootstrap.dist.js"></script>
  <script src="~/vendor/libs/pickr/pickr.dist.js"></script>
  <script src="~/js/site.dist.js"></script>
</environment>
<environment exclude="Development">
  <script src="~/vendor/libs/popper/popper.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/js/bootstrap.dist.js" asp-append-version="true"></script>
  <script src="~/vendor/libs/pickr/pickr.dist.js" asp-append-version="true"></script>
  <script src="~/js/site.dist.js" asp-append-version="true"></script>
</environment>

Layout Usage

You can set the layout in two ways:

  1. Layout for the entire app - set Layout property in the Pages/_ViewStart.cshtml file.
  2. Layout for the specific page - set Layout property in the .cshtml file.
  3. For ex. We have added custom options in LayoutExample pages

You can find Navbar, Sidebar and Footer templates in the Pages/Layouts/Sections directory.


Layout Options

Layout options are useful to create layout with custom options as per different layout examples. You can add this options at page level or layout level as well.

Find all the layout options with it's value below :

Data Options DataType Data Values
TempData["menuHorizontal"] Boolean true | false
ViewData["container"] String "container-fluid" | "container-xxl"
ViewData["containerNav"] String "container-fluid" | "container-xxl"
ViewData["customizerHidden"] String "customizer-hide"
ViewData["footerFixed"] String "layout-footer-fixed"
ViewData["menuCollapsed"] String "layout-menu-collapsed"
ViewData["menuFixed"] String "layout-menu-fixed"
ViewData["navbarType"] String "layout-navbar-fixed"
ViewData["contentNavbar"] Boolean true | false
ViewData["isFlex"] Boolean true | false
ViewData["isMenu"] Boolean true | false
ViewData["isNavbar"] Boolean true | false
ViewData["navbarHideToggle"] Boolean true | false
ViewData["isFront"] Boolean true | false
ViewData["contentType"] String "container-fluid" | "container-xxl"

Dark Layout

To set default layout to dark layout, just need to update wwwroot\js\config.js file's defaultStyle option :

if (typeof TemplateCustomizer !== 'undefined') {
  window.templateCustomizer = new TemplateCustomizer({
    ...
    defaultTheme: 'dark',
    ...
  });
}

RTL

To set default layout to RTL layout, just need to update wwwroot\js\config.js file's defaultTextDir option :

if (typeof TemplateCustomizer !== 'undefined') {
  window.templateCustomizer = new TemplateCustomizer({
    ...
    defaultTextDir: 'rtl',
    ...
  });
}