Example of Types in ASP.NET MVC Toast Control
This sample demonstrates 4-predefined toast colors for various scenarios which can be using CSS class.
@Html.UiToast(new UiToastOptions { Id = "toast_type", Position = UiToastPosition.TopRight, Timeout = 5000, OnClose = "onclose" })
@Html.UiButton(new UiButtonOptions { Id = "info_Toast", Text = "Info Message", Color = UiButtonColor.Info })
@Html.UiButton(new UiButtonOptions { Id = "success_Toast", Text = "Success Message", Color = UiButtonColor.Success })
@Html.UiButton(new UiButtonOptions { Id = "warning_Toast", Text = "Warning Message", Color = UiButtonColor.Warning })
@Html.UiButton(new UiButtonOptions { Id = "error_Toast", Text = "Danger Message", Color = UiButtonColor.Danger })
@Html.UiButton(new UiButtonOptions { Id = "hideToast", Text = "Hide All" })
<style>
.toast-default-section .control_wrapper, .toast-pos-section .control_wrapper, .toast-api-section .control_wrapper, .toast-template-section .control_wrapper { max-width: 760px; margin: 0 auto; padding: 20px 0; }
.toast-center { text-align: center; }
.toast-center .ui-btn, .toast-center button { margin: 5px; }
.toast-panel-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.toast-icon-meeting { background-color: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 12h-5v5h5v-5zM16 1v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2h-1V1h-2zm3 18H5V8h14v11z'/%3E%3C/svg%3E") no-repeat center / contain; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 12h-5v5h5v-5zM16 1v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2h-1V1h-2zm3 18H5V8h14v11z'/%3E%3C/svg%3E") no-repeat center / contain; }
#toast_types button { margin: 5px; min-width: 160px; }
</style>
<div class="control-section toast-default-section">
<div class="control_wrapper">
@Html.UiToast(new UiToastOptions { Id = "toast_type", Position = UiToastPosition.TopRight, Timeout = 5000, OnClose = "onclose" })
<div id="toast_types" class="toast-center">
<div>
@Html.UiButton(new UiButtonOptions { Id = "info_Toast", Text = "Info Message", Color = UiButtonColor.Info })
@Html.UiButton(new UiButtonOptions { Id = "success_Toast", Text = "Success Message", Color = UiButtonColor.Success })
@Html.UiButton(new UiButtonOptions { Id = "warning_Toast", Text = "Warning Message", Color = UiButtonColor.Warning })
@Html.UiButton(new UiButtonOptions { Id = "error_Toast", Text = "Danger Message", Color = UiButtonColor.Danger })
</div>
<div style="padding-top: 15px">
@Html.UiButton(new UiButtonOptions { Id = "hideToast", Text = "Hide All" })
</div>
</div>
</div>
</div>
<script>
// Syncfusion: each button shows a toast of its kind; Hide All (and a click elsewhere) closes them
var toasts = [
{ title: "Warning!", content: "There was a problem with your network connection.", severity: "warning" },
{ title: "Success!", content: "Your message has been sent successfully.", severity: "success" },
{ title: "Error!", content: "A problem has been occurred while submitting your data.", severity: "error" },
{ title: "Information!", content: "Please read the comments carefully.", severity: "info" }
];
var btnEleHide = document.getElementById('hideToast');
function toastObj() { return window.Lumen.get('toast_type'); }
function showToast(model) { toastObj().show(model); }
function onclose() { }
var buttons = { info_Toast: 3, warning_Toast: 0, success_Toast: 1, error_Toast: 2 };
document.addEventListener('click', function (e) {
var hit = e.target.closest('button');
if (hit && buttons[hit.id] !== undefined) { showToast(toasts[buttons[hit.id]]); return; }
if (hit && hit.id === 'hideToast') { toastObj().hideAll(); return; }
if (toastObj()) { toastObj().hideAll(); }
});
window.addEventListener('load', function () { setTimeout(function () { showToast(toasts[3]); }, 500); });
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ToastController : Controller
{
// The page is Views/Toast/Types.cshtml; it draws what ViewData holds.
public ActionResult Types()
{
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 toast supports the following 4 different essential colors for various situations. Here we have achieved success, danger, warning, info notifications with corresponding icon and text message. All the classes should be added with .e-toast class.
- Information - The e-toast-info class applies the color and background for showing toast information.
- Success - The e-toast-success class applies the color and background for notifying success action.
- Warning - The e-toast-warning class applies the color and background for showing warning message.
- Danger - The e-toast-danger class applies the color and background for showing error/failure toast.