Example of Sidebar With List View in ASP.NET MVC Sidebar Control
The Sidebar ListView sample demonstrates customizing the Sidebar with ListView. Click on the hamburger menu icon to expand/collapse the sidebar. Click the ListView item to see the corresponding item details.
Before getting into any programming language, one should have basic knowledge about HTML, CSS, and JavaScript. These are the basic building blocks of web designing. HTML describes the structure of a web page whereas CSS describes the presentation of the web page.
@Html.UiToolbar(new UiToolbarOptions { Id = "listToolbar", Items = (List<UiToolbarItem>)ViewData["ListToolItems"], OnClick = "toggleSidebar" })
<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-pic { width: 28px; height: 28px; border-radius: 50%; background: var(--ui-row-hover-bg); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="sb-toolbar">
@Html.UiToolbar(new UiToolbarOptions { Id = "listToolbar", Items = (List<UiToolbarItem>)ViewData["ListToolItems"], OnClick = "toggleSidebar" })
</div>
<div class="sb-frame">
@using (Html.BeginUiSidebar(new UiSidebarOptions { Id = "listSidebar", Contained = true, Type = UiSidebarType.Push, IsOpen = true, Width = "250px" }))
{
<ul class="sb-list e-template-list" id="listSidebarList">
@foreach (var data in (List<NavigationDemoController.SidebarLanguage>)ViewData["ListData"])
{
<li><button type="button" data-description="@data.Description"><span class="e-avatar sb-pic" aria-hidden="true">@data.Text.Substring(0, 2)</span><span class="sb-text">@data.Text</span></button></li>
}
</ul>
}
<div class="sb-main maincontent">
<div id="listContent" class="content">
Before getting into any programming language, one should have basic knowledge about HTML, CSS, and JavaScript. These are the basic building blocks of web designing. HTML describes the structure of a web page whereas CSS describes the presentation of the web page.
</div>
</div>
</div>
</div>
<script>
// Syncfusion: the Menu button of the Toolbar toggles the Sidebar
function toggleSidebar(item) {
if (item.id === 'menu') { window.Lumen.get('listSidebar').toggle(); }
}
</script>
<script>
// Syncfusion: selecting an item of the ListView shows its description
document.getElementById('listSidebarList').addEventListener('click', function (e) {
var button = e.target.closest('button');
if (!button) { return; }
document.getElementById('listContent').textContent = button.getAttribute('data-description');
this.querySelectorAll('button').forEach(function (b) { b.removeAttribute('aria-current'); });
button.setAttribute('aria-current', 'true');
});
</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/SidebarWithListView.cshtml; it draws what ViewData holds.
public ActionResult SidebarWithListView()
{
ViewData["ListToolItems"] = 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'>Language</div></div>") }
};
ViewData["ListData"] = new List<SidebarLanguage>
{
new SidebarLanguage { Text = "JavaScript", Description = "JavaScript (JS) is an interpreted computer programming language. It was originally implemented as part of web browsers so that client-side scripts could interact with the user, control the browser, communicate asynchronously, and alter the document content that was displayed. However, it has recently become common in both game development and the creation of desktop applications." },
new SidebarLanguage { Text = "TypeScript", Description = "It is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript is an open-source, object-oriented programing language. It contains all elements of JavaScript. It is a language designed for large-scale JavaScript application development, which can be executed on any browser, any Host, and any Operating System. TypeScript is a language as well as a set of tools. TypeScript is the ES6 version of JavaScript with some additional features." },
new SidebarLanguage { Text = "Angular", Description = "Angular is a platform and framework for building single-page client applications using HTML and TypeScript. Angular is written in TypeScript. It implements core and optional functionality as a set of TypeScript libraries that you import into your applications." },
new SidebarLanguage { Text = "React", Description = "React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It lets you compose complex UIs from small and isolated pieces of code called “components”. It can also render on the server using Node." },
new SidebarLanguage { Text = "Vue", Description = "A progressive framework for building user interfaces. It is incrementally adoptable. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries or existing projects. On the other hand, Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries." }
};
return View();
}
/// <summary>An item of the ListView sample's list.</summary>
public class SidebarLanguage
{
public string Text { get; set; }
public string Description { 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 can allow to render custom components like TreeView, ListView, Menu, etc.
In this sample, the ListView component is placed inside the Sidebar for navigation. Click the ListView item to see the corresponding item details.