Example of Customization in ASP.NET MVC Message Control
This sample demonstrates the customization of the icon, content alignment, and appearance in the ASP.NET MVC Message.
Content Alignment
Custom Message with Icon
@Html.UiMessage(new UiMessageOptions { Id = "msg-content-left", Severity = UiSeverity.Success, Content = "Your license has been activated successfully" })
@Html.UiMessage(new UiMessageOptions { Id = "msg-content-center", Severity = UiSeverity.Warning, Content = "The license will expire today", ContentAlignment = UiContentAlignment.Center })
@Html.UiMessage(new UiMessageOptions { Id = "msg-content-right", Severity = UiSeverity.Error, Content = "The license key is invalid", ContentAlignment = UiContentAlignment.Right })
@Html.UiMessage(new UiMessageOptions { Id = "msg_icon", Severity = UiSeverity.Info, CssClass = "custom", IconCss = "msg-icon-star", Content = "Essential JS 2 is a modern JavaScript UI Controls library built from the ground up to be lightweight, responsive, modular, and touch friendly. It is written in the TypeScript and has no external dependencies. It also includes complete support for Angular, React, Vue, ASP.NET MVC, and ASP.NET Core frameworks." })
<style>
.msg-content-section { margin: 0 auto; max-width: 520px; padding-top: 10px; }
.msg-content-section .ui-message { margin: 10px 0; }
.msg-content-section h4 { margin: 12px 0 4px; font-size: 14px; }
.msg-hidden { display: none; }
.property-section .property-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.msg-custom-section .msg-content-section { max-width: 400px; }
.msg-icon-star { background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 17.27 18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 17.27 18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z'/%3E%3C/svg%3E") center / contain no-repeat; }
.custom.ui-message { background-color: #ffe3fb; border-color: #e0c7dd; color: #b42d79; }
.custom.ui-message .ui-message-icon { color: #b42d79; }
</style>
<div class="control-section msg-custom-section">
<div class="msg-content-section">
<h4>Content Alignment</h4>
@Html.UiMessage(new UiMessageOptions { Id = "msg-content-left", Severity = UiSeverity.Success, Content = "Your license has been activated successfully" })
@Html.UiMessage(new UiMessageOptions { Id = "msg-content-center", Severity = UiSeverity.Warning, Content = "The license will expire today", ContentAlignment = UiContentAlignment.Center })
@Html.UiMessage(new UiMessageOptions { Id = "msg-content-right", Severity = UiSeverity.Error, Content = "The license key is invalid", ContentAlignment = UiContentAlignment.Right })
</div>
<div class="msg-content-section">
<h4>Custom Message with Icon</h4>
@Html.UiMessage(new UiMessageOptions { Id = "msg_icon", Severity = UiSeverity.Info, CssClass = "custom", IconCss = "msg-icon-star", Content = "Essential JS 2 is a modern JavaScript UI Controls library built from the ground up to be lightweight, responsive, modular, and touch friendly. It is written in the TypeScript and has no external dependencies. It also includes complete support for Angular, React, Vue, ASP.NET MVC, and ASP.NET Core frameworks." })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MessageController : Controller
{
// The page is Views/Message/Customization.cshtml; it draws what ViewData holds.
public ActionResult Customization()
{
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 Message control’s content can be aligned by adding predefined classes. By default, messages are aligned to the left. The other available alignments are center and right, achieved by adding, e-content-center and e-content-right.
The icon and appearance can be customized at the application level by using the CssClass property.
In this sample, the Message control’s predefined content is aligned based on the CssClass property. Also, this control is rendered with a custom severity icon and custom appearance.