Example of Custom Dialogs in ASP.NET MVC Dialog Control
This example demonstrates the different types of Dialog like alert, confirm, and prompt. The buttons "Alert", "Confirm", and "Prompt" will be shown after closing the alert Dialog. These buttons are used to open the corresponding Dialogs.
Low Battery
10% of battery remaining
Delete Multiple Items
Are you sure you want to permanently delete these items ?
Join Wi-Fi network
| SSID: |
| AndroidAP |
| Password: |
@Html.UiButton(new UiButtonOptions { Id = "alertBtn", Text = "Alert", CssClass = "dlgbtn" })
@Html.UiButton(new UiButtonOptions { Id = "confirmBtn", Text = "Confirm", CssClass = "dlgbtn" })
@Html.UiButton(new UiButtonOptions { Id = "promptBtn", Text = "Prompt", CssClass = "dlgbtn" })
@Html.UiDialog(new UiDialogOptions
{
Id = "alert_dialog", Target = "target", Header = "Low Battery", Content = "10% of battery remaining", CloseOnEscape = true, Width = "250px", Animation = UiDialogAnimation.None,
Buttons = { new UiDialogButton { Text = "Dismiss", IsPrimary = true } }
})
@Html.UiDialog(new UiDialogOptions
{
Id = "confirm_dialog", Target = "target", Header = "Delete Multiple Items", Content = "Are you sure you want to permanently delete these items ?", ShowCloseIcon = true, CloseOnEscape = true, Width = "400px", Animation = UiDialogAnimation.None,
Buttons = { new UiDialogButton { Text = "Yes", IsPrimary = true }, new UiDialogButton { Text = "No" } }
})
@Html.UiDialog(new UiDialogOptions
{
Id = "prompt_dialog", Target = "target", Header = "Join Wi-Fi network", ShowCloseIcon = true, CloseOnEscape = true, Width = "330px", Animation = UiDialogAnimation.None,
Template = @<table class="Table"><tbody><tr><td>SSID:</td></tr><tr><td><b>AndroidAP</b></td></tr><tr><td>Password:</td></tr><tr><td>@Html.UiTextBox("password", null, new UiTextBoxOptions { Type = UiTextBoxType.Password })</td></tr></tbody></table>,
Buttons = { new UiDialogButton { Text = "Connect", IsPrimary = true }, new UiDialogButton { Text = "Cancel" } }
})
@Html.UiTextBox("password", null, new UiTextBoxOptions { Type = UiTextBoxType.Password })
<style>
.control-section { padding-left: 10px; }
#target { position: relative; height: 100%; min-height: 350px; }
.dlgbtn { margin-right: 10px; }
.animate { display: inline-block; margin: 0 6px 6px 0; }
</style>
<div id="target" class="control-section">
@Html.UiButton(new UiButtonOptions { Id = "alertBtn", Text = "Alert", CssClass = "dlgbtn" })
@Html.UiButton(new UiButtonOptions { Id = "confirmBtn", Text = "Confirm", CssClass = "dlgbtn" })
@Html.UiButton(new UiButtonOptions { Id = "promptBtn", Text = "Prompt", CssClass = "dlgbtn" })
@Html.UiDialog(new UiDialogOptions
{
Id = "alert_dialog", Target = "target", Header = "Low Battery", Content = "10% of battery remaining", CloseOnEscape = true, Width = "250px", Animation = UiDialogAnimation.None,
Buttons = { new UiDialogButton { Text = "Dismiss", IsPrimary = true } }
})
@Html.UiDialog(new UiDialogOptions
{
Id = "confirm_dialog", Target = "target", Header = "Delete Multiple Items", Content = "Are you sure you want to permanently delete these items ?", ShowCloseIcon = true, CloseOnEscape = true, Width = "400px", Animation = UiDialogAnimation.None,
Buttons = { new UiDialogButton { Text = "Yes", IsPrimary = true }, new UiDialogButton { Text = "No" } }
})
@Html.UiDialog(new UiDialogOptions
{
Id = "prompt_dialog", Target = "target", Header = "Join Wi-Fi network", ShowCloseIcon = true, CloseOnEscape = true, Width = "330px", Animation = UiDialogAnimation.None,
Template = @<table class="Table"><tbody><tr><td>SSID:</td></tr><tr><td><b>AndroidAP</b></td></tr><tr><td>Password:</td></tr><tr><td>@Html.UiTextBox("password", null, new UiTextBoxOptions { Type = UiTextBoxType.Password })</td></tr></tbody></table>,
Buttons = { new UiDialogButton { Text = "Connect", IsPrimary = true }, new UiDialogButton { Text = "Cancel" } }
})
</div>
<script>
// Syncfusion: each button opens its dialog
document.addEventListener('click', function (e) {
['alert', 'confirm', 'prompt'].forEach(function (kind) {
if (e.target.closest('#' + kind + 'Btn')) { window.Lumen.get(kind + '_dialog').show(); }
});
});
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DialogController : Controller
{
// The page is Views/Dialog/CustomDialogs.cshtml; it draws what ViewData holds.
public ActionResult CustomDialogs()
{
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 Dialog control is used to display messages such as supplementary content like images and text, and an interactive content like form components within a web page. The following are the two types of Dialogs:
- Alert - Used to show errors, warnings, and information that needs user awareness.
- Prompt - Used to get input from the user.
- Confirmation - Used to get approval from user that appears before any critical action.