Example of Listview in ASP.NET MVC Badge Control
This sample demonstrates the integration of badges into listview component to display the new e-mails count.
${text}
${messages}
- Primary
- Social
- Promotions
- Updates
- Starred
- Important
- Sent
- Outbox
- Drafts
@Html.UiListView(new UiListViewOptions { Id = "lists", Width = "320px", Template = "#badgeListTemplate", DataSource = (IEnumerable<object>)ViewData["dataSource"] })
<style>
.sample_container { max-width: 900px; margin: 0 auto; padding: 24px 0; }
.badge-block { display: inline-block; position: relative; margin: 14px 18px; vertical-align: middle; }
.badge-showcase { display: inline-block; width: 180px; margin: 10px; padding: 16px 8px; border: 1px solid var(--ui-border); border-radius: 8px; background: var(--ui-surface); text-align: center; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.badge-showcase .text { margin-top: 12px; font-size: 12px; }
.badge-showcase button { position: relative; }
.margin { margin: 12px 0 4px; }
.fontSize { font-weight: 600; font-size: 15px; }
.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; }
.whatsapp { background: #25d366; } .twitter { background: #1da1f2; } .facebook { background: #1877f2; } .skype { background: #00aff0; } .pinterest { background: #e60023; } .contact { background: #6b7280; }
.notify-list-row { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.notify-list-row .ui-badge { margin-left: 8px; }
.notify-list-row span:empty { display: none; }
</style>
<template id="badgeListTemplate">
<span class="notify-list-row">
<span class="list_text">${text}</span>
<span class="${badge}">${messages}</span>
</span>
</template>
<div class="control-section">
<div class="sample_container badge-list">
@Html.UiListView(new UiListViewOptions { Id = "lists", Width = "320px", Template = "#badgeListTemplate", DataSource = (IEnumerable<object>)ViewData["dataSource"] })
</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/ListView.cshtml; it draws what ViewData holds.
public ActionResult ListView()
{
List<object> data = new List<object>();
data.Add(new { id = "p_01", Value = "p_01", text = "Primary", messages = "3 New", badge = "ui-badge ui-badge-primary", type = "Primary" });
data.Add(new { id = "p_02", Value = "p_02", text = "Social", messages = "27 New", badge = "ui-badge ui-badge-secondary", type = "Primary" });
data.Add(new { id = "p_03", Value = "p_03", text = "Promotions", messages = "7 New", badge = "ui-badge ui-badge-success", type = "Primary" });
data.Add(new { id = "p_04", Value = "p_04", text = "Updates", messages = "13 New", badge = "ui-badge ui-badge-info", type = "Primary" });
data.Add(new { id = "p_05", Value = "p_05", text = "Starred", messages = "", badge = "", type = "All Labels" });
data.Add(new { id = "p_06", Value = "p_06", text = "Important", messages = "2 New", badge = "ui-badge ui-badge-danger", type = "All Labels" });
data.Add(new { id = "p_07", Value = "p_07", text = "Sent", messages = "", badge = "", type = "All Labels" });
data.Add(new { id = "p_08", Value = "p_08", text = "Outbox", messages = "", badge = "", type = "All Labels" });
data.Add(new { id = "p_09", Value = "p_09", text = "Drafts", messages = "7 New", badge = "ui-badge ui-badge-warning", type = "All Labels" });
ViewData["dataSource"] = data;
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>
The badge can be integrated into the listview with the help of the templates. With badges there are so many real-time use cases that the listview can be used to achieve different applications.
Here, default badges are used and there is no need to customize the badge size because component will automatically adjust the size based on the container element.
In this samples, different types of colours are used to indicate their priorities of their notification.