Example of Listview in ASP.NET MVC Avatar Control
This sample demonstrates the integration of avatar component into listview to create contacts applications.
- Contacts
- A Andrew
-
John
- M Margaret
-
Michael
- N Nancy
-
Robert
-
Steven
@Html.UiAvatar(new UiAvatarOptions { Text = person.avatar, Size = UiAvatarSize.Small, Shape = UiAvatarShape.Circle })
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/" + person.pic + ".png"), Size = UiAvatarSize.Small, Shape = UiAvatarShape.Circle, Title = person.text })
<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; }
.avatar-list { list-style: none; margin: 30px 0; padding: 0; border: 1px solid var(--ui-border); border-radius: 4px; background: var(--ui-surface); }
.avatar-list-header { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--ui-border); }
.avatar-list-item { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--ui-border); }
.avatar-list-item:last-child { border-bottom: 0; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="sample_container" style="max-width: 360px">
<ul id="letterAvatarList" class="avatar-list" aria-label="Contacts">
<li class="avatar-list-header">Contacts</li>
@foreach (var person in ((IEnumerable<LayoutDemoController.AvatarContact>)ViewData["dataSource"]).OrderBy(p => p.text))
{
<li class="avatar-list-item">
@if (person.avatar != "")
{
@Html.UiAvatar(new UiAvatarOptions { Text = person.avatar, Size = UiAvatarSize.Small, Shape = UiAvatarShape.Circle })
}
else
{
@Html.UiAvatar(new UiAvatarOptions { ImageUrl = Url.Content("~/Content/avatar/images/" + person.pic + ".png"), Size = UiAvatarSize.Small, Shape = UiAvatarShape.Circle, Title = person.text })
}
<span class="list-text">@person.text</span>
</li>
}
</ul>
</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/ListView.cshtml; it draws what ViewData holds.
public ActionResult ListView()
{
ViewData["dataSource"] = new List<AvatarContact>
{
new AvatarContact { text = "Robert", id = "s_01", avatar = "", pic = "pic04" },
new AvatarContact { text = "Nancy", id = "s_02", avatar = "N", pic = "" },
new AvatarContact { text = "John", id = "s_03", avatar = "", pic = "pic01" },
new AvatarContact { text = "Andrew", id = "s_04", avatar = "A", pic = "" },
new AvatarContact { text = "Michael", id = "s_05", avatar = "", pic = "pic02" },
new AvatarContact { text = "Steven", id = "s_06", avatar = "", pic = "pic03" },
new AvatarContact { text = "Margaret", id = "s_07", avatar = "M", pic = "" }
};
return View();
}
/// <summary>A contact of the Avatar ListView sample (Syncfusion builds anonymous objects).</summary>
public class AvatarContact
{
public string text { get; set; }
public string id { get; set; }
public string avatar { get; set; }
public string pic { 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 avatar can be used with the other component to create various applications. Here, the avatar is used to display images or the initials of the people in the contact lists.
Here, the xsmall avatar is used in circle type. To change the size of the avatar to xsmall and circle style add .e-avatar-xsmall and .e-avatar-circle