Example of Positioning in ASP.NET MVC Dialog Control
This example demonstrates how to position the dialog control. Select the appropriate radio button to position where the dialog is displayed. The current position of the dialog is at the bottom. Enable the "open dialog" button to reopen the dialog if it is closed.
Choose a Dialog Position
Position: { X: "Center", Y: "Bottom" }
@Html.UiButton(new UiButtonOptions { Id = "dialogBtn", Text = "Open Dialog", CssClass = "dlgbtn" })
@Html.UiDialog(new UiDialogOptions
{
Id = "positionDialog", Target = "target", Header = "Choose a Dialog Position", ShowCloseIcon = true, CloseOnEscape = true, Width = "427px", Animation = UiDialogAnimation.None,
PositionX = UiDialogPositionX.Center, PositionY = UiDialogPositionY.Bottom, OnOpen = "dialogOpen", OnClose = "dialogClose",
Template = @<div><table id="poschange">@foreach (string[] place in (List<string[]>)ViewData["places"]) { <tr>@foreach (string x in new[] { "Left", "Center", "Right" }) { <td><label><input type="radio" name="xy" value="@(x + " " + place[0])" @(x == "Center" && place[0] == "Bottom" ? "checked" : "") onchange="onChangeHandler(this.value)" /> @(x + " " + place[0])</label></td> } </tr> }</table><p id="posvalue">Position: { X: "Center", Y: "Bottom" }</p></div>
})
<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; }
#poschange td { padding: 4px 10px; }
#posvalue { margin: 10px 0 0; font-size: 13px; }
</style>
<div id="target" class="control-section">
@Html.UiButton(new UiButtonOptions { Id = "dialogBtn", Text = "Open Dialog", CssClass = "dlgbtn" })
@Html.UiDialog(new UiDialogOptions
{
Id = "positionDialog", Target = "target", Header = "Choose a Dialog Position", ShowCloseIcon = true, CloseOnEscape = true, Width = "427px", Animation = UiDialogAnimation.None,
PositionX = UiDialogPositionX.Center, PositionY = UiDialogPositionY.Bottom, OnOpen = "dialogOpen", OnClose = "dialogClose",
Template = @<div><table id="poschange">@foreach (string[] place in (List<string[]>)ViewData["places"]) { <tr>@foreach (string x in new[] { "Left", "Center", "Right" }) { <td><label><input type="radio" name="xy" value="@(x + " " + place[0])" @(x == "Center" && place[0] == "Bottom" ? "checked" : "") onchange="onChangeHandler(this.value)" /> @(x + " " + place[0])</label></td> } </tr> }</table><p id="posvalue">Position: { X: "Center", Y: "Bottom" }</p></div>
})
</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("positionDialog").show(); } });
</script>
<script>
// Syncfusion: the radio buttons set the position of the Dialog
function onChangeHandler(value) {
var parts = value.split(' ');
window.Lumen.get('positionDialog').setPosition(parts[0], parts[1]);
document.getElementById('posvalue').textContent = 'Position: { X: "' + parts[0] + '", Y: "' + parts[1] + '" }';
}
</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/Positioning.cshtml; it draws what ViewData holds.
public ActionResult Positioning()
{
ViewData["places"] = new List<string[]> { new[] { "Top" }, new[] { "Center" }, new[] { "Bottom" } };
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>
By default, the dialog is displayed in the center of the target container. Use the position property to set location where the dialog displays relative to the target. The property point-out the horizontal and vertical coordinates. You can set position with specific X and Y coordinates in pixel values.