Example of API in ASP.NET MVC Sidebar Control
The Sidebar API sample demonstrates how to customize the Sidebar component by using its properties from the property pane. Select any combination of properties from the property pane to customize the Sidebar. Click on the hamburger menu icon to expand/collapse the sidebar.
The Sidebar component is a collapsible side content placed along with the main content either in left or right side of the page.
Toggle - Toggles the Sidebar to be open or closed state.
Position - Allows to place the sidebar in right or left side of the page.
Types - Specifies the act of expanding or collapsing the sidebar with main content.
Closing on document click - Allows to collapse / close the sidebar on document click.
Backdrop - Sets the backdrop over the main content area on open / expanded state.
@Html.UiButton(new UiButtonOptions { Id = "apitogglesidebar", Text = "Toggle", Color = UiButtonColor.Primary })
@Html.UiButton(new UiButtonOptions { Id = "positionBtn", Text = "Left", Color = UiButtonColor.Primary })
@Html.UiDropDownList("apidd", new UiDropDownListOptions { Width = "100px", Value = "Push", Items = ((string[])ViewData["Types"]).Select(text => new UiListItem(text, text)).ToList(), OnChange = "onChange" })
@Html.UiButton(new UiButtonOptions { Id = "documentElement", Text = "False", Color = UiButtonColor.Primary })
@Html.UiButton(new UiButtonOptions { Id = "backDropElement", Text = "False", Color = UiButtonColor.Primary })
<style>
.sb-toolbar .ui-toolbar { border: 1px solid var(--ui-border); border-bottom: 0; border-radius: 4px 4px 0 0; }
.sb-frame { position: relative; display: flex; height: 380px; overflow: hidden; border: 1px solid var(--ui-border); border-radius: 0 0 4px 4px; background: var(--ui-surface); }
.sb-frame.sb-alone { border-radius: 4px; }
.sb-frame > .ui-sidebar { z-index: 20; }
.sb-main { flex: 1 1 auto; min-width: 0; overflow: auto; padding: 15px; box-sizing: border-box; font-size: 14px; }
.sb-side { padding: 15px; }
.e-folder-name { font-size: 16px; font-weight: 600; padding-left: 6px; }
.e-user-name { font-size: 14px; padding-right: 6px; }
.e-user-avatar { display: inline-flex; width: 32px; height: 32px; align-items: center; justify-content: center; border-radius: 50%; background: var(--ui-accent); color: var(--ui-on-accent); font-weight: 600; }
.sb-mail, .sb-list { list-style: none; margin: 0; padding: 0; }
.sb-mail li { display: grid; grid-template-columns: 40px 1fr; column-gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--ui-border); }
.sb-mail .e-avatar { grid-row: span 3; align-self: center; width: 36px; height: 36px; border-radius: 50%; background: var(--ui-row-hover-bg); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.sb-mail .e-list-item-header { font-weight: 600; }
.sb-mail .e-list-content { color: var(--ui-text); }
.sb-mail .e-list-text { color: var(--ui-muted); font-size: 12px; }
.sb-heading { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.sb-paragraph { margin: 0 0 16px; text-align: justify; }
.sb-list li button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.sb-list li button:hover { background: var(--ui-row-hover-bg); }
.sb-list li button[aria-current="true"] { background: var(--ui-row-hover-bg); font-weight: 600; }
.sb-list .e-icons { flex: none; width: 24px; height: 24px; font-size: 20px; }
.sb-list .sb-text { white-space: nowrap; overflow: hidden; }
.ui-sidebar-dock:not(.ui-sidebar-open) .sb-text { display: none; }
.sb-api-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; }
.sb-api-row p { margin: 0; flex: 1 1 auto; }
.sb-api-row > div { flex: none; }
.title { font-weight: 500; font-size: 18px; margin: 0 0 6px; }
.title-header { font-size: 18px; padding-bottom: 15px; }
.sub-title { font-size: 16px; }
.sb-close, .sb-hamburger { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 18px; }
.sb-close { float: right; }
.sb-hamburger { float: left; margin-right: 10px; font-size: 24px; }
.sb-hamburger .e-icons { width: 24px; height: 24px; font-size: 24px; }
</style>
<div class="control-section">
<div class="sb-frame sb-alone apimaincontent">
@using (Html.BeginUiSidebar(new UiSidebarOptions { Id = "apisidebar", Contained = true, Type = UiSidebarType.Push, Width = "220px", CssClass = "default-sidebar" }))
{
<div class="sb-side">
<div class="title-header"><div style="display:inline-block"> Sidebar </div> <button type="button" id="apiclose" class="sb-close" aria-label="Close">×</button></div>
<div class="sub-title">
The ASP.NET MVC Sidebar is an expandable and collapsible component that typically acts as a side container to place primary or secondary content alongside the main content. It provides flexible options that can be shown and hidden using the toggle button.
</div>
</div>
}
<div id="wrapper" class="sb-main">
<div class="list-group-item">
<button type="button" id="apihamburger" class="sb-hamburger" aria-label="Toggle the Sidebar"><span class="e-icons e-menu"></span></button>
<div class="title">Overview</div>
<p> The Sidebar component is a collapsible side content placed along with the main content either in left or right side of the page. </p>
<div class="title">Options</div>
<div class="sb-api-row"><p><b>Toggle</b> - Toggles the Sidebar to be open or closed state.</p><div>@Html.UiButton(new UiButtonOptions { Id = "apitogglesidebar", Text = "Toggle", Color = UiButtonColor.Primary })</div></div>
<div class="sb-api-row"><p><b>Position</b> - Allows to place the sidebar in right or left side of the page.</p><div>@Html.UiButton(new UiButtonOptions { Id = "positionBtn", Text = "Left", Color = UiButtonColor.Primary })</div></div>
<div class="sb-api-row"><p><b>Types</b> - Specifies the act of expanding or collapsing the sidebar with main content.</p><div>@Html.UiDropDownList("apidd", new UiDropDownListOptions { Width = "100px", Value = "Push", Items = ((string[])ViewData["Types"]).Select(text => new UiListItem(text, text)).ToList(), OnChange = "onChange" })</div></div>
<div class="sb-api-row"><p><b>Closing on document click</b> - Allows to collapse / close the sidebar on document click.</p><div>@Html.UiButton(new UiButtonOptions { Id = "documentElement", Text = "False", Color = UiButtonColor.Primary })</div></div>
<div class="sb-api-row"><p><b>Backdrop</b> - Sets the backdrop over the main content area on open / expanded state.</p><div>@Html.UiButton(new UiButtonOptions { Id = "backDropElement", Text = "False", Color = UiButtonColor.Primary })</div></div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
var sidebar = function () { return window.Lumen.get('apisidebar'); };
var flag = function (id) { return window.Lumen.get(id); };
// the close button is inside the Sidebar, which a setter draws again: the click is heard on the document
document.addEventListener('click', function (e) { if (e.target.closest('#apiclose')) { sidebar().close(); } });
document.getElementById('apitogglesidebar').addEventListener('click', function () { sidebar().toggle(); });
document.getElementById('apihamburger').addEventListener('click', function () { sidebar().toggle(); });
// Syncfusion: each button flips one property of the Sidebar and its own label
document.getElementById('positionBtn').addEventListener('click', function () {
var right = this.textContent.trim() === 'Left';
flag('positionBtn').setContent(right ? 'Right' : 'Left');
sidebar().setPosition(right ? 'Right' : 'Left');
});
document.getElementById('documentElement').addEventListener('click', function () {
var on = this.textContent.trim() === 'False';
flag('documentElement').setContent(on ? 'True' : 'False');
sidebar().setCloseOnDocumentClick(on);
});
document.getElementById('backDropElement').addEventListener('click', function () {
var on = this.textContent.trim() === 'False';
flag('backDropElement').setContent(on ? 'True' : 'False');
sidebar().setShowBackdrop(on);
});
});
function onChange(value) {
if (value) { window.Lumen.get('apisidebar').setType(value); }
}
</script>
<script>
(function (window, document) {
'use strict';
document.querySelectorAll('.navigation-sample [data-nav-api]').forEach(function (button) {
button.addEventListener('click', function () {
var control = window.Lumen.get('navApi');
if (!control) { window.NavigationSampleLog('Control is not ready'); return; }
var action = button.getAttribute('data-nav-api');
if (action === 'open') { control.open(); }
if (action === 'close') { control.close(); }
if (action === 'toggle') { control.toggle(); }
window.NavigationSampleLog('Sidebar API: ' + action);
});
});
})(window, document);
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class SidebarController : Controller
{
// The page is Views/Sidebar/API.cshtml; it draws what ViewData holds.
public ActionResult API()
{
ViewData["Types"] = new string[] { "Over", "Push" };
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
In this demo, the default Sidebar is rendered with minimal configuration. This sample can be customized further with the combination of Sidebar properties. For example,
- The Sidebar can be opened or closed by clicking on the toggle button.
- The Sidebar position can be changed by clicking on the position button.
- The Sidebar types can be changed from the Dropdown List.
- The Sidebar can be collapsed or closed on document click from the provided options.
- The Sidebar overlay can be enabled or disabled by clicking on the Backdrop button.