Example of Modal in ASP.NET MVC Dialog Control
This example demonstrates the modal behavior of Dialog control. Choose "Close on overlay" option from property panel to decide whether the Dialog will be closed on click on the overlay. Click on “Open” button to show the Dialog again if it is closed.
Software Update
Your current software version is up to date.
Close on overlay click
@Html.UiButton(new UiButtonOptions { Id = "dialogButton", Text = "Open" })
@Html.UiDialog(new UiDialogOptions
{
Id = "modal_dialog", Target = "target", IsModal = true, Header = "Software Update", Content = "Your current software version is up to date.",
CloseOnEscape = true, Width = "335px", Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "OK", IsPrimary = true } }
})
@Html.UiCheckBox("checkbox", false, new UiCheckBoxOptions { Id = "checkbox", OnChange = "onChange" })
<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; }
.property-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; }
</style>
<div id="target" class="control-section">
@Html.UiButton(new UiButtonOptions { Id = "dialogButton", Text = "Open" })
@Html.UiDialog(new UiDialogOptions
{
Id = "modal_dialog", Target = "target", IsModal = true, Header = "Software Update", Content = "Your current software version is up to date.",
CloseOnEscape = true, Width = "335px", Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "OK", IsPrimary = true } }
})
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Close on overlay click</span> @Html.UiCheckBox("checkbox", false, new UiCheckBoxOptions { Id = "checkbox", OnChange = "onChange" })</div>
</div>
<script>
// Syncfusion: the Open button is hidden while the dialog is open
function dialogOpen() { document.getElementById('dialogButton').style.display = 'none'; }
function dialogClose() { document.getElementById('dialogButton').style.display = 'inline-block'; }
document.addEventListener('click', function (e) { if (e.target.closest('#dialogButton')) { window.Lumen.get("modal_dialog").show(); } });
</script>
<script>
// Syncfusion: the check box sets closeOnOverlayClick of the Dialog
function onChange(checkedNow) { window.Lumen.get('modal_dialog').setCloseOnOverlayClick(checkedNow); }
</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/Modal.cshtml; it draws what ViewData holds.
public ActionResult Modal()
{
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>
A modal prevents the access to the parent application, so the user must interact with the Dialog before continuing the parent application.