Example of Accordion in ASP.NET MVC Badge Control
This sample demonstrates the integration of badges into accordion component to display the thread notification count.
Robert 7 New
Message Thread. Message Thread.
Kevin 27 New
Message Thread. Message Thread.
Eric 2 New
Message Thread. Message Thread.
Peter 14 New
Message Thread. Message Thread.
@Html.UiBadge(new UiBadgeOptions { Content = count, Color = UiBadgeColor.Success, AriaLabel = count + " messages" })
@Html.UiAccordion(new UiAccordionOptions { Id = "accordion", 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; }
.notify-acc-head { display: inline-flex; align-items: center; gap: 8px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section default">
<div class="sample_container badge-accordion">
@{
var items = new List<UiAccordionItem>();
foreach (NotificationsDemoController.BadgeRow p in (List<NotificationsDemoController.BadgeRow>)ViewData["accordionItems"])
{
string name = p.Text; string count = p.Count;
items.Add(new UiAccordionItem { Expanded = p.Open, HeaderTemplate = @<span class="notify-acc-head">@name @Html.UiBadge(new UiBadgeOptions { Content = count, Color = UiBadgeColor.Success, AriaLabel = count + " messages" })</span>, Content = "Message Thread. Message Thread." });
}
}
@Html.UiAccordion(new UiAccordionOptions { Id = "accordion", 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/Accordion.cshtml; it draws what ViewData holds.
public ActionResult Accordion()
{
List<BadgeRow> accItems = new List<BadgeRow>();
accItems.Add(new BadgeRow { Text = "Robert", Count = "7 New", Open = true });
accItems.Add(new BadgeRow { Text = "Kevin", Count = "27 New", Open = false });
accItems.Add(new BadgeRow { Text = "Eric", Count = "2 New", Open = false });
accItems.Add(new BadgeRow { Text = "Peter", Count = "14 New", Open = false });
ViewData["accordionItems"] = accItems;
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 accordion with help of the templates to display the count of new message in the message thread. Here, the Success badge is used in the accordion. To add success badge, add .e-badge-success.