Example of Template in ASP.NET MVC Dialog Control
This example demonstrates the template functionalities of the dialog component. The dialog header and footer is configured with HTML template. The typed content will be replaced every time when clicking the "send" button.
Nancy
Greetings Nancy! When will you share me the source files of the project?
@Html.UiButton(new UiButtonOptions { Id = "targetButton", Text = "OPEN DIALOG" })
@Html.UiDialog(new UiDialogOptions
{
Id = "dialogTemplate", Target = "target", Width = "435px", Height = "75%", ShowCloseIcon = true, CloseOnEscape = true, OnOpen = "dialogOpen", OnClose = "dialogClose",
Header = "Nancy",
Template = @<div class="dialogContent"><span class="dialogText">Greetings Nancy! When will you share me the source files of the project?</span></div>,
FooterTemplate = @<div class="dialog-footer"><input id="inVal" class="template-input" type="text" placeholder="Enter your message here!" />@Html.UiButton(new UiButtonOptions { Id = "sendButton", Text = "Send", Color = UiButtonColor.Primary })</div>
})
@Html.UiButton(new UiButtonOptions { Id = "sendButton", Text = "Send", Color = UiButtonColor.Primary })
<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; }
.dialog-footer { display: flex; gap: 8px; width: 100%; }
.template-input { flex: 1; padding: 6px 8px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
</style>
<div id="target" class="control-section" style="height: 100%">
@Html.UiButton(new UiButtonOptions { Id = "targetButton", Text = "OPEN DIALOG" })
@Html.UiDialog(new UiDialogOptions
{
Id = "dialogTemplate", Target = "target", Width = "435px", Height = "75%", ShowCloseIcon = true, CloseOnEscape = true, OnOpen = "dialogOpen", OnClose = "dialogClose",
Header = "Nancy",
Template = @<div class="dialogContent"><span class="dialogText">Greetings Nancy! When will you share me the source files of the project?</span></div>,
FooterTemplate = @<div class="dialog-footer"><input id="inVal" class="template-input" type="text" placeholder="Enter your message here!" />@Html.UiButton(new UiButtonOptions { Id = "sendButton", Text = "Send", Color = UiButtonColor.Primary })</div>
})
</div>
<script>
// Syncfusion: the Open button is hidden while the dialog is open
function dialogOpen() { document.getElementById('targetButton').style.display = 'none'; }
function dialogClose() { document.getElementById('targetButton').style.display = 'inline-block'; }
document.addEventListener('click', function (e) { if (e.target.closest('#targetButton')) { window.Lumen.get("dialogTemplate").show(); } });
</script>
<script>
// Syncfusion: the typed text replaces the message every time Send is clicked (or Enter is pressed)
function updateTextValue() {
var entered = document.getElementById('inVal');
var text = document.querySelector('.dialogText');
if (entered.value !== '') {
text.textContent = entered.value;
entered.value = '';
}
}
document.addEventListener('click', function (e) { if (e.target.closest('#sendButton')) { updateTextValue(); } });
document.addEventListener('keydown', function (e) { if (e.key === 'Enter' && e.target.id === 'inVal') { updateTextValue(); } });
</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/Template.cshtml; it draws what ViewData holds.
public ActionResult Template()
{
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 displays HTML template content on the header and footer. The user can set any HTML element as header and footer with the usage of content and footer template properties.