Example of Badge in ASP.NET MVC Avatar Control
This sample demonstrates the integration of avatar component with badges to create notification avatars.
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XSmall, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "6", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "6 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Small, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "12", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "12 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "46", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "46 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Large, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "82", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "82 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XLarge, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "99+", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "99+ notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XSmall, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "6", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "6 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Small, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "12", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "12 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "46", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "46 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Large, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "82", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "82 notifications" })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XLarge, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "99+", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "99+ notifications" })
<style>
.sample_container { margin: 0 auto; }
.avatar-block { display: inline-block; vertical-align: top; }
.avatar-showcase { display: block; box-sizing: border-box; padding: 5px; margin: 5px; border: 1px solid var(--ui-border); border-radius: 8px; background: var(--ui-surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); }
.avatar-showcase .card-content { display: flex; align-items: center; justify-content: space-evenly; gap: 6px; padding: 10px 0; text-align: center; }
.avatar-showcase .card-content .ui-avatar { font-size: 18px; }
.avatar-sub-block { display: inline-block; position: relative; margin: 7px; }
</style>
<div class="control-section">
<div class="sample_container avatar-badge" style="max-width: 840px">
<div class="avatar-block">
<div class="avatar-showcase" style="width: 400px; max-width: 100%">
<div class="card-content">
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XSmall, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "6", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "6 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Small, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "12", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "12 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "46", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "46 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Large, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "82", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "82 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XLarge, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "99+", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "99+ notifications" })
</div>
</div>
</div>
</div>
<div class="circleAvatar avatar-block">
<div class="avatar-showcase" style="width: 400px; max-width: 100%">
<div class="card-content">
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XSmall, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "6", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "6 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Small, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "12", Color = UiBadgeColor.Primary, Shape = UiBadgeShape.Circle, Position = UiBadgePosition.Notification, AriaLabel = "12 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "46", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "46 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.Large, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "82", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "82 notifications" })
</div>
<div class="avatar-sub-block">
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/pic01.png"), Size = UiAvatarSize.XLarge, Shape = UiAvatarShape.Circle, Title = "Profile picture" })
@Html.UiBadge(new UiBadgeOptions { Content = "99+", Color = UiBadgeColor.Primary, Position = UiBadgePosition.Notification, AriaLabel = "99+ notifications" })
</div>
</div>
</div>
</div>
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class AvatarController : Controller
{
// The page is Views/Avatar/Badge.cshtml; it draws what ViewData holds.
public ActionResult Badge()
{
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 Avatar can be used with badges to have notification to indicate the new activities. The container needs to position: relative to achieve the notifications styled avatar. In this sample, the wrapper is applied with position: relative with avatar and badge elements inside it.
Since the avatar is a supportive and dependent component it can be used in many ways and can have wide variety of use-case.