Example of Toolbar in ASP.NET MVC Badge Control
This sample demonstrates the integration of badges into toolbar component to display mails, requests etc.
@Html.UiBadge(new UiBadgeOptions { Content = count, Color = color, Position = UiBadgePosition.Notification, AriaLabel = count + " items" })
@Html.UiToolbar(new UiToolbarOptions { Id = "toolbar", Items = items })
<style>
.sample_container { max-width: 900px; margin: 0 auto; padding: 24px 0; }
.svg_icons { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; color: #fff; font-weight: 700; font-size: 16px; }
.message { background: #7c3aed; } .facebook { background: #1877f2; } .contact { background: #6b7280; }
#toolbar .ui-tb-items { padding-top: 10px; }
#toolbar .ui-badge-host { margin-right: 18px; }
.badge-toolbar .header { font-weight: 600; margin-right: 12px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="sample_container badge-toolbar">
@{
var items = new List<UiToolbarItem>();
items.Add(new UiToolbarItem { Type = UiToolbarItemType.Input, Template = @<span class="header">Notification</span> });
foreach (NotificationsDemoController.BadgeRow row in (List<NotificationsDemoController.BadgeRow>)ViewData["items"])
{
string icon = row.Icon; string letter = row.Letter; string count = row.Count;
UiBadgeColor color = (UiBadgeColor)System.Enum.Parse(typeof(UiBadgeColor), row.Color);
items.Add(new UiToolbarItem { Type = UiToolbarItemType.Input, Template = @<span class="ui-badge-host"><span class="@icon svg_icons" aria-hidden="true">@letter</span>@Html.UiBadge(new UiBadgeOptions { Content = count, Color = color, Position = UiBadgePosition.Notification, AriaLabel = count + " items" })</span> });
}
}
@Html.UiToolbar(new UiToolbarOptions { Id = "toolbar", Items = items })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class BadgeController : Controller
{
// The page is Views/Badge/Toolbar.cshtml; it draws what ViewData holds.
public ActionResult Toolbar()
{
List<BadgeRow> alignItems = new List<BadgeRow>();
alignItems.Add(new BadgeRow { Icon = "message", Letter = "M", Count = "35", Color = "Primary" });
alignItems.Add(new BadgeRow { Icon = "contact", Letter = "U", Count = "28", Color = "Success" });
alignItems.Add(new BadgeRow { Icon = "facebook", Letter = "L", Count = "98", Color = "Info" });
ViewData["items"] = alignItems;
return View();
}
public class BadgeRow
{
public string Text { get; set; }
public string Count { get; set; }
public string Color { get; set; }
public string Icon { get; set; }
public string Letter { get; set; }
public bool Open { 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 badge can be integrated into the toolbar to display the notifications of custom buttons, particular thing needs user attention. Here, the SVG icons are used as the target for the badge elements to display notifications.