Example of Default Functionalities in ASP.NET MVC Sidebar Control
The Sidebar sample demonstrates the default functionalities of the Sidebar. Click on the hamburger menu icon to expand/collapse the sidebar. Click the TreeView node to see the corresponding folders mail details.
@Html.UiToolbar(new UiToolbarOptions { Id = "toolbar", Items = (List<UiToolbarItem>)ViewData["DefToolItems"], OnClick = "toggleSidebar" })
@Html.UiTreeView(new UiTreeViewOptions { Id = "treeObj", Nodes = (List<UiTreeNode>)ViewData["TreeData"], OnNodeSelected = "onSelect" })
<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; }
</style>
<div class="control-section">
<div class="sb-toolbar">
@Html.UiToolbar(new UiToolbarOptions { Id = "toolbar", Items = (List<UiToolbarItem>)ViewData["DefToolItems"], OnClick = "toggleSidebar" })
</div>
<div class="sb-frame">
@using (Html.BeginUiSidebar(new UiSidebarOptions { Id = "sidebarObj", Contained = true, Type = UiSidebarType.Push, IsOpen = true, Width = "260px", CssClass = "default-sidebar" }))
{
<div class="sb-side">
@Html.UiTreeView(new UiTreeViewOptions { Id = "treeObj", Nodes = (List<UiTreeNode>)ViewData["TreeData"], OnNodeSelected = "onSelect" })
</div>
}
<div class="sb-main maincontent">
<ul id="listView" class="sb-mail"></ul>
</div>
</div>
</div>
<script>
// Syncfusion: the Menu button of the Toolbar toggles the Sidebar
function toggleSidebar(item) {
if (item.id === 'menu') { window.Lumen.get('sidebarObj').toggle(); }
}
</script>
<script>
var mailData = @Html.Raw(Json.Encode(ViewData["MailData"]));
// Syncfusion: selecting a folder of the TreeView fills the ListView with its mails
function onSelect(node) {
var mails = mailData[node.text];
if (!mails) { return; }
document.getElementById('listView').innerHTML = mails.map(function (m) {
return '<li><span class="e-avatar">' + m.Text.split(' ').map(function (w) { return w[0]; }).join('') + '</span>' +
'<span class="e-list-item-header">' + m.Text + '</span><span class="e-list-content">' + m.Subject + '</span><span class="e-list-text">' + m.Message + '</span></li>';
}).join('');
}
onSelect({ text: 'Inbox' });
</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/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
ViewData["DefToolItems"] = new List<UiToolbarItem>
{
new UiToolbarItem { Id = "menu", IconCss = "e-icons e-menu", TooltipText = "Menu" },
new UiToolbarItem { Type = UiToolbarItemType.Input, HtmlContent = new HtmlString("<div class='e-folder'><div class='e-folder-name'>Webmail</div></div>") },
new UiToolbarItem { Align = UiToolbarAlign.Right, Type = UiToolbarItemType.Input, HtmlContent = new HtmlString("<div><div class='e-user-name'>John</div></div>") },
new UiToolbarItem { Align = UiToolbarAlign.Right, Type = UiToolbarItemType.Input, HtmlContent = new HtmlString("<div class='image-container'><span class='e-user-avatar'>J</span></div>") }
};
ViewData["TreeData"] = new List<UiTreeNode>
{
new UiTreeNode { Id = "1", Text = "Favorites", Expanded = true, Children = { new UiTreeNode { Id = "2", Text = "Inbox", Selected = true }, new UiTreeNode { Id = "3", Text = "Sent Items" } } },
new UiTreeNode { Id = "5", Text = "John", Expanded = true, Children = { new UiTreeNode { Id = "6", Text = "Inbox" }, new UiTreeNode { Id = "7", Text = "Drafts" }, new UiTreeNode { Id = "8", Text = "Deleted Items" }, new UiTreeNode { Id = "9", Text = "Sent Items" }, new UiTreeNode { Id = "12", Text = "Outbox" } } }
};
ViewData["MailData"] = new Dictionary<string, List<SidebarMail>>
{
{ "Inbox", new List<SidebarMail>
{
new SidebarMail { Id = "1", Text = "Albert Lives", Subject = "Business dinner invitation", Message = "Hello Uta Morgan," },
new SidebarMail { Id = "2", Text = "Ila Russo", Subject = "Opening for Sales Manager", Message = "Hello Jelani Moreno," },
new SidebarMail { Id = "3", Text = "Garth Owen", Subject = "Application for Job Title", Message = "Hello Ila Russo," },
new SidebarMail { Id = "4", Text = "Ursula Patterson", Subject = "Programmer Position Application", Message = "Hello Kerry Best," },
new SidebarMail { Id = "5", Text = "Nichole Rivas", Subject = "Annual Conference", Message = "Hi Igor Mccoy," }
} },
{ "Sent Items", new List<SidebarMail>
{
new SidebarMail { Id = "11", Text = "Gemma Roberson", Subject = "Apology for late response email", Message = "Hello Colette Wooten," },
new SidebarMail { Id = "12", Text = "Ann Garza", Subject = "Application for Job Title", Message = "Hello Kerry Best," },
new SidebarMail { Id = "13", Text = "Alfonso Burnett", Subject = "Anything I can help with", Message = "Hello Otto Ashley," },
new SidebarMail { Id = "14", Text = "Rogan Espinoza", Subject = "Assistant Marketing Department", Message = "Hello Kerry Best," },
new SidebarMail { Id = "15", Text = "Sierra Kerr", Subject = "Application for Transfer", Message = "Hi Halee Lindsey," }
} },
{ "Drafts", new List<SidebarMail>
{
new SidebarMail { Id = "21", Text = "Chaim Barber", Subject = "We launched new Product!", Message = "Hello Cameran Roth," },
new SidebarMail { Id = "22", Text = "Lara Knox", Subject = "Request for meeting appointment email", Message = "Hello Mona Bates," },
new SidebarMail { Id = "23", Text = "Igor Mccoy", Subject = "Thank you", Message = "Hello Kerry Best," },
new SidebarMail { Id = "24", Text = "Patricia Boyle", Subject = "Sales Team", Message = "Hello Amelia Curtis," },
new SidebarMail { Id = "25", Text = "Zachery Peters", Subject = "Today’s meeting schedule", Message = "Hi Leslie Juarez," }
} },
{ "Deleted Items", new List<SidebarMail>
{
new SidebarMail { Id = "31", Text = "Elijah Berry", Subject = "Apology marketing email", Message = "Dear Kerry Best," },
new SidebarMail { Id = "32", Text = "Cameran Newman", Subject = "Business appointment request", Message = "Hello Mona Bates," },
new SidebarMail { Id = "33", Text = "Amity Slater", Subject = "Business dinner invitation", Message = "Hello Kerry Best," },
new SidebarMail { Id = "34", Text = "Leo Cooley", Subject = "Apology Email for Wrong Order", Message = "Hi Athena Mcintosh," },
new SidebarMail { Id = "35", Text = "Halee Lindsey", Subject = "Apology for late response email", Message = "Hi Fletcher Beck," }
} },
{ "Outbox", new List<SidebarMail>
{
new SidebarMail { Id = "41", Text = "Willow Frye", Subject = "Out of Office", Message = "Hello Maggy Randall," },
new SidebarMail { Id = "42", Text = "Regan Haney", Subject = "Project Manager Interview", Message = "Hello Kerry Best," },
new SidebarMail { Id = "43", Text = "Stella Calderon", Subject = "Proposition for a new business", Message = "Hello Gail Pierce," },
new SidebarMail { Id = "44", Text = "Xanthus Harmon", Subject = "Performance appraisal announcement", Message = "Dear Clare Heath," },
new SidebarMail { Id = "45", Text = "Cheyenne Cline", Subject = "Office Holiday", Message = "Hi Fletcher Beck," }
} }
};
return View();
}
/// <summary>A mail of the Default Functionalities sample's list.</summary>
public class SidebarMail
{
public string Id { get; set; }
public string Text { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
}
}
}
@* 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>
The 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 based on user interactions. Any type of HTML content or component can be placed in the Sidebar for quick access and easy navigation, like quick references, menus, lists, and tree views.
In this demo, the Sidebar is populated as like webmail with folder structure.