Example of Default Functionalities in ASP.NET MVC Toast Control
This sample demonstrates the basic layout of a Toast to show simple notification and hide them.
@Html.UiToast(new UiToastOptions { Id = "toast_default", Position = UiToastPosition.TopRight, Timeout = 5000, OnClose = "onclose" })
@Html.UiButton(new UiButtonOptions { Id = "toastBtnShow", Text = "Show Toasts" })
@Html.UiButton(new UiButtonOptions { Id = "toastBtnHide", 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; }
</style>
<div class="control-section toast-default-section">
<div class="control_wrapper">
@Html.UiToast(new UiToastOptions { Id = "toast_default", Position = UiToastPosition.TopRight, Timeout = 5000, OnClose = "onclose" })
<div class="toast-center" id="toastBtnDefault">
@Html.UiButton(new UiButtonOptions { Id = "toastBtnShow", Text = "Show Toasts" })
@Html.UiButton(new UiButtonOptions { Id = "toastBtnHide", Text = "Hide All" })
</div>
</div>
</div>
<script>
// Syncfusion: Show Toasts shows the meeting reminder, Hide All (and a click elsewhere) closes the toasts
var btnEleShow = document.getElementById('toastBtnShow');
var btnEleHide = document.getElementById('toastBtnHide');
function toastObj() { return window.Lumen.get('toast_default'); }
function showMeeting() {
toastObj().show({ title: 'Adaptive Tiles Meeting', content: 'Conference Room 01 / Building 135 10:00 AM-10:30 AM', icon: 'toast-icon-meeting' });
}
function onclose() {
}
btnEleShow.addEventListener('click', showMeeting);
btnEleHide.addEventListener('click', function () { toastObj().hideAll(); });
document.addEventListener('click', function (e) { if (!e.target.closest('#toastBtnShow') && toastObj()) { toastObj().hideAll(); } });
window.addEventListener('load', function () { setTimeout(showMeeting, 500); });
</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 ToastController : Controller
{
// The page is Views/Toast/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
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 Toast is a notification pop-up used to display on the desired position with required message and header icons.
- The header text is set using title property.
- Information to be displayed is set using content property.