Example of Ajax Content in ASP.NET MVC Dialog Control
This example demonstrates that the content of dialog can be loaded from external HTML file. Click "more details" on dialog to load the content dynamically from external HTML file. Click “open” to show the dialog again, if it is closed.
What's Coming from Microsoft this Fall
On October 17, Microsoft will release its Fall Creators Update for the Windows 10 platform. Much like its previous counterpart, the Spring Creators Update, the release is set to deliver more features to Windows 10 for both developers and users with particular emphasis this time around on app modernization, mixed realityand gamedevelopment and software updates. App modernization is the term Microsoft used in its press event toencompass thefeatures that will affect most Windows 10 users and developers. The updates primarily serve to make using Windows 10
@Html.UiButton(new UiButtonOptions { Id = "dialogBtn", Text = "Open" })
@Html.UiDialog(new UiDialogOptions
{
Id = "ajax_dialog", Target = "target", Header = "What's Coming from Microsoft this Fall", Content = "On October 17, Microsoft will release its Fall Creators Update for the Windows 10 platform. Much like its previous counterpart, the Spring Creators Update, the release is set to deliver more features to Windows 10 for both developers and users with particular emphasis this time around on app modernization, mixed realityand gamedevelopment and software updates. App modernization is the term Microsoft used in its press event toencompass thefeatures that will affect most Windows 10 users and developers. The updates primarily serve to make using Windows 10",
ShowCloseIcon = true, CloseOnEscape = true, Width = "500px", OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "More Details", IsPrimary = true, OnClick = "dlgButtonClick", CloseDialog = false } }
})
<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; }
</style>
<div class="control-section" id="target">
<div class="control-wrapper">
@Html.UiButton(new UiButtonOptions { Id = "dialogBtn", Text = "Open" })
@Html.UiDialog(new UiDialogOptions
{
Id = "ajax_dialog", Target = "target", Header = "What's Coming from Microsoft this Fall", Content = "On October 17, Microsoft will release its Fall Creators Update for the Windows 10 platform. Much like its previous counterpart, the Spring Creators Update, the release is set to deliver more features to Windows 10 for both developers and users with particular emphasis this time around on app modernization, mixed realityand gamedevelopment and software updates. App modernization is the term Microsoft used in its press event toencompass thefeatures that will affect most Windows 10 users and developers. The updates primarily serve to make using Windows 10",
ShowCloseIcon = true, CloseOnEscape = true, Width = "500px", OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "More Details", IsPrimary = true, OnClick = "dlgButtonClick", CloseDialog = false } }
})
</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("ajax_dialog").show(); } });
</script>
<script>
// Syncfusion: More Details opens the Microsoft page
function dlgButtonClick() { window.open('https://www.syncfusion.com/company/about-us'); }
</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/AjaxContent.cshtml; it draws what ViewData holds.
public ActionResult AjaxContent()
{
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 user can load dialog's content dynamically from external source like external file using Fetch library. The Fetch library can make the request and load dialog's content using its success event.