Example of Multiple Dialogs in ASP.NET MVC Dialog Control
This example demonstrates how to display multiple dialogs one over the other. The second dialog is configured with draggable behavior to adjust its position. You can invoke the second dialog from first dialog's button. Enable the "open dialog" button to reopen the dialog if the first dialog is closed.
First Dialog
This is the first dialog and acts as a parent dialog, you can open the second (child) dialog by clicking 'Next'.
Second Dialog
This is the second dialog and act as a child dialog.
@Html.UiButton(new UiButtonOptions { Id = "dialogBtn", Text = "Open Dialog", CssClass = "dlgbtn" })
@Html.UiDialog(new UiDialogOptions
{
Id = "firstDialog", Target = "target", Visible = true, Header = "First Dialog", Content = "This is the first dialog and acts as a parent dialog, you can open the second (child) dialog by clicking 'Next'.",
ShowCloseIcon = true, CloseOnEscape = true, Width = "330px", Height = "260px", Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "Next", IsPrimary = true, OnClick = "dlgButtonClick", CloseDialog = false } }
})
@Html.UiDialog(new UiDialogOptions
{
Id = "secondDialog", Target = "target", IsModal = true, Header = "Second Dialog", Content = "This is the second dialog and act as a child dialog.",
ShowCloseIcon = true, CloseOnEscape = true, Width = "285px", Height = "215px", Animation = UiDialogAnimation.None,
Buttons = { new UiDialogButton { Text = "Close", IsPrimary = true, OnClick = "dlg2ButtonClick" } }
})
<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; }
#dialogBtn { display: none; }
</style>
<div id="target" class="control-section">
@Html.UiButton(new UiButtonOptions { Id = "dialogBtn", Text = "Open Dialog", CssClass = "dlgbtn" })
@Html.UiDialog(new UiDialogOptions
{
Id = "firstDialog", Target = "target", Visible = true, Header = "First Dialog", Content = "This is the first dialog and acts as a parent dialog, you can open the second (child) dialog by clicking 'Next'.",
ShowCloseIcon = true, CloseOnEscape = true, Width = "330px", Height = "260px", Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "Next", IsPrimary = true, OnClick = "dlgButtonClick", CloseDialog = false } }
})
@Html.UiDialog(new UiDialogOptions
{
Id = "secondDialog", Target = "target", IsModal = true, Header = "Second Dialog", Content = "This is the second dialog and act as a child dialog.",
ShowCloseIcon = true, CloseOnEscape = true, Width = "285px", Height = "215px", Animation = UiDialogAnimation.None,
Buttons = { new UiDialogButton { Text = "Close", IsPrimary = true, OnClick = "dlg2ButtonClick" } }
})
</div>
<script>
// Syncfusion: the Open button is hidden while the dialog is open
function dialogOpen() { document.getElementById('dialogBtn').style.display = 'none'; }
function dialogClose() { document.getElementById('dialogBtn').style.display = 'inline-block'; }
document.addEventListener('click', function (e) { if (e.target.closest('#dialogBtn')) { window.Lumen.get("firstDialog").show(); } });
</script>
<script>
// Syncfusion: Next opens the second dialog over the first; Close closes it
function dlgButtonClick() { window.Lumen.get('secondDialog').show(); }
function dlg2ButtonClick() { window.Lumen.get('secondDialog').hide(); }
</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/MultipleDialogs.cshtml; it draws what ViewData holds.
public ActionResult MultipleDialogs()
{
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>
You can configure the dialog as a parent and child, and invoke the child dialog from its parent dialog. In addition, multiple dialogs can be shown at a time in a page. The Z- index order will be controlled automatically in the browser and manually using the zIndex property.