Example of Draggable in ASP.NET MVC Dialog Control
This example demonstrates the drag-and-drop operation of the dialog control. To begin drag-and-drop operation, select a dialog's header using mouse and drop them in the desired location. The dialog can be dragged within the sample container. Enable the "open dialog" button to reopen the dialog if it is closed.
Drag Me!!!
This is a dialog with draggable support.
@Html.UiButton(new UiButtonOptions { Id = "dialogBtn", Text = "Open Dialog", CssClass = "dlgbtn" })
@Html.UiDialog(new UiDialogOptions
{
Id = "draggableDialog", Target = "target", Visible = true, IsModal = true, Header = "Drag Me!!!", Content = "This is a dialog with draggable support.",
ShowCloseIcon = true, CloseOnEscape = true, Width = "300px", AllowDragging = true, Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose"
})
<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 = "draggableDialog", Target = "target", Visible = true, IsModal = true, Header = "Drag Me!!!", Content = "This is a dialog with draggable support.",
ShowCloseIcon = true, CloseOnEscape = true, Width = "300px", AllowDragging = true, Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose"
})
</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("draggableDialog").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/Draggable.cshtml; it draws what ViewData holds.
public ActionResult Draggable()
{
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 drag-and-drop operation is enabled using the allowDragging property. when you configure the target property, the dialog can be dragged within its target container alone. The drag-and-drop feature is used to reposition the dialog dynamically.