Example of Icons in ASP.NET MVC Message Control
This sample demonstrates the visibility customization of severity and close icons of the ASP.NET MVC Message control. Click the close icon to hide the message. Click the button to restore the hidden message. Check or uncheck the check box to show or hide the visibility of the severity icon. Check or uncheck the check box to show or hide the visibility of the close icon.
@Html.UiButton(new UiButtonOptions { Id = "btn1", Text = "Show Default Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_default_icon", Severity = UiSeverity.Default, Content = "Editing is restricted", ShowCloseIcon = true, OnClosed = "defaultClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn2", Text = "Show Info Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_info_icon", Severity = UiSeverity.Info, Content = "Please read the comments carefully", ShowCloseIcon = true, OnClosed = "infoClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn3", Text = "Show Success Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_success_icon", Severity = UiSeverity.Success, Content = "Your message has been sent successfully", ShowCloseIcon = true, OnClosed = "successClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn4", Text = "Show Warning Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_warning_icon", Severity = UiSeverity.Warning, Content = "There was a problem with your network connection", ShowCloseIcon = true, OnClosed = "warningClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn5", Text = "Show Error Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_error_icon", Severity = UiSeverity.Error, Content = "A problem occurred while submitting your data", ShowCloseIcon = true, OnClosed = "errorClosed" })
@Html.UiCheckBox("showIcon", true, new UiCheckBoxOptions { Id = "showIcon", Label = "Show Icon", OnChange = "severityIconChange" })
@Html.UiCheckBox("showCloseIcon", true, new UiCheckBoxOptions { Id = "showCloseIcon", Label = "Show Close Icon", OnChange = "closeIconChange" })
<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; }
</style>
<div class="control-section msg-icon-section">
<div class="msg-content-section">
@Html.UiButton(new UiButtonOptions { Id = "btn1", Text = "Show Default Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_default_icon", Severity = UiSeverity.Default, Content = "Editing is restricted", ShowCloseIcon = true, OnClosed = "defaultClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn2", Text = "Show Info Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_info_icon", Severity = UiSeverity.Info, Content = "Please read the comments carefully", ShowCloseIcon = true, OnClosed = "infoClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn3", Text = "Show Success Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_success_icon", Severity = UiSeverity.Success, Content = "Your message has been sent successfully", ShowCloseIcon = true, OnClosed = "successClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn4", Text = "Show Warning Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_warning_icon", Severity = UiSeverity.Warning, Content = "There was a problem with your network connection", ShowCloseIcon = true, OnClosed = "warningClosed" })
@Html.UiButton(new UiButtonOptions { Id = "btn5", Text = "Show Error Message", Variant = UiButtonVariant.Outline, CssClass = "msg-hidden" })
@Html.UiMessage(new UiMessageOptions { Id = "msg_error_icon", Severity = UiSeverity.Error, Content = "A problem occurred while submitting your data", ShowCloseIcon = true, OnClosed = "errorClosed" })
</div>
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row">@Html.UiCheckBox("showIcon", true, new UiCheckBoxOptions { Id = "showIcon", Label = "Show Icon", OnChange = "severityIconChange" })</div>
<div class="property-row">@Html.UiCheckBox("showCloseIcon", true, new UiCheckBoxOptions { Id = "showCloseIcon", Label = "Show Close Icon", OnChange = "closeIconChange" })</div>
</div>
<script>
// Syncfusion: a closed message leaves its Show button; the check boxes show or hide the icon and the close icon of all five
var kinds = ['default', 'info', 'success', 'warning', 'error'];
function messageOf(kind) { return window.Lumen.get('msg_' + kind + '_icon'); }
function buttonOf(kind) { return document.getElementById('btn' + (kinds.indexOf(kind) + 1)); }
function closedOf(kind) { buttonOf(kind).classList.remove('msg-hidden'); }
function defaultClosed() { closedOf('default'); }
function infoClosed() { closedOf('info'); }
function successClosed() { closedOf('success'); }
function warningClosed() { closedOf('warning'); }
function errorClosed() { closedOf('error'); }
kinds.forEach(function (kind) {
buttonOf(kind).addEventListener('click', function () { messageOf(kind).show(); buttonOf(kind).classList.add('msg-hidden'); });
});
function severityIconChange(checked) { kinds.forEach(function (kind) { messageOf(kind).setShowIcon(checked); }); }
function closeIconChange(checked) { kinds.forEach(function (kind) { messageOf(kind).setShowCloseIcon(checked); }); }
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MessageController : Controller
{
// The page is Views/Message/Icons.cshtml; it draws what ViewData holds.
public ActionResult Icons()
{
return View();
}
private ActionResult Show(string method)
{
NotificationSample sample = (NotificationSample)ViewBag.NotificationSample;
// A sample keeps its data in a Prepare<Page> method (NotificationsDemoController.Samples.cs); it puts what the page reads in ViewData.
string page = sample.Source.Substring(sample.Source.LastIndexOf('_') + 1);
System.Reflection.MethodInfo prepare = GetType().GetMethod(method + page, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (prepare != null) { prepare.Invoke(this, null); }
return View("PreparedSample", ViewData.Model);
}
}
}
@* 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>
@* Notificationss with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
The Message control can be rendered with and without the severity and close icons. The close icon is used to hide the message.
In this sample, the Message control is rendered with a severity icon and a close icon. The visibility of the severity icon is handled by the ShowIcon property. The visibility of the close icon is handled by the ShowCloseIcon property.