Example of Components inside Dialog in ASP.NET MVC Dialog Control
This example demonstrates how to integrate other ASP.NET MVC UI components within the dialog control. In the below example, The dialog component renders with the Grid, Schedule, Chart, Rich Text Editor, Tabs and Form components.
Syncfusion Components inside Dialog
- Meeting 10:00 – 11:30
- Lunch 12:30 – 13:30
- Review 15:00 – 16:00
Add Customer Details
@Html.UiButton(new UiButtonOptions { Id = "normalbtn", Text = "Open" })
@Html.UiDialog(new UiDialogOptions
{
Id = "defaultDialog", Target = "target", Header = "Syncfusion Components inside Dialog", ShowCloseIcon = true, CloseOnEscape = true, Width = "720px", Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "OK", IsPrimary = true }, new UiDialogButton { Text = "CANCEL" } },
Template = @<div>
@Html.UiTabs(new UiTabsOptions
{
Id = "dialogTabs",
Items = new List<UiTabItem>
{
new UiTabItem { Header = "Grid", HtmlContent = Html.UiGrid(new UiGridOptions
{
Id = "DefaultFunctionalities", Data = (List<LayoutDemoController.DialogOrder>)ViewData["DataSource"], AllowPaging = true,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "OrderID", HeaderText = "Order ID", Type = UiColumnType.Number, IsPrimaryKey = true, Width = 100 },
new UiGridColumn { Field = "CustomerID", HeaderText = "Customer Name", Width = 150 },
new UiGridColumn { Field = "Freight", HeaderText = "Freight", Type = UiColumnType.Number, Format = "N2", Width = 110 },
new UiGridColumn { Field = "ShipCountry", HeaderText = "Ship Country", Width = 140 }
}
}) },
new UiTabItem { Header = "Scheduler", HtmlContent = new HtmlString("<ul class=\"dialog-agenda\"><li><b>Meeting</b> 10:00 – 11:30</li><li><b>Lunch</b> 12:30 – 13:30</li><li><b>Review</b> 15:00 – 16:00</li></ul>") },
new UiTabItem { Header = "Chart", HtmlContent = Html.UiChart(new UiChartOptions
{
Id = "chart", Data = (IEnumerable<object>)ViewData["ChartData"], Title = "Inflation - Consumer Price",
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { Minimum = 0, Maximum = 100, Interval = 20, LabelFormat = "{value}%" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "x", YName = "y", Name = "Germany", Marker = new UiChartMarker { Visible = true, Width = 10, Height = 10 } },
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "x", YName = "y1", Name = "England", Marker = new UiChartMarker { Visible = true, Width = 10, Height = 10 } }
}
}) },
new UiTabItem { Header = "Rich Text Editor", HtmlContent = Html.UiRichTextEditor(new UiRichTextEditorOptions { Id = "rte", Value = "<p>The Rich Text Editor component is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content. Users can format their content using standard toolbar commands.</p>" }) },
new UiTabItem { Header = "Forms", HtmlContent = new HtmlString("<div class=\"dialog-form\"><div class=\"form-title\"><span>Add Customer Details</span></div><p><label>User Name<br /><input type=\"text\" class=\"dialog-input\" /></label></p><p><label>Date of Birth<br /><input type=\"date\" class=\"dialog-input\" /></label></p><p><label>Address<br /><textarea rows=\"2\" class=\"dialog-input\"></textarea></label></p><p><button type=\"submit\" class=\"ui-btn ui-btn-primary\">Add Customer</button> <button type=\"reset\" class=\"ui-btn\">Clear</button></p></div>") }
}
})
</div>
})
@Html.UiTabs(new UiTabsOptions
{
Id = "dialogTabs",
Items = new List<UiTabItem>
{
new UiTabItem { Header = "Grid", HtmlContent = Html.UiGrid(new UiGridOptions
{
Id = "DefaultFunctionalities", Data = (List<LayoutDemoController.DialogOrder>)ViewData["DataSource"], AllowPaging = true,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "OrderID", HeaderText = "Order ID", Type = UiColumnType.Number, IsPrimaryKey = true, Width = 100 },
new UiGridColumn { Field = "CustomerID", HeaderText = "Customer Name", Width = 150 },
new UiGridColumn { Field = "Freight", HeaderText = "Freight", Type = UiColumnType.Number, Format = "N2", Width = 110 },
new UiGridColumn { Field = "ShipCountry", HeaderText = "Ship Country", Width = 140 }
}
}) },
new UiTabItem { Header = "Scheduler", HtmlContent = new HtmlString("<ul class=\"dialog-agenda\"><li><b>Meeting</b> 10:00 – 11:30</li><li><b>Lunch</b> 12:30 – 13:30</li><li><b>Review</b> 15:00 – 16:00</li></ul>") },
new UiTabItem { Header = "Chart", HtmlContent = Html.UiChart(new UiChartOptions
{
Id = "chart", Data = (IEnumerable<object>)ViewData["ChartData"], Title = "Inflation - Consumer Price",
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { Minimum = 0, Maximum = 100, Interval = 20, LabelFormat = "{value}%" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "x", YName = "y", Name = "Germany", Marker = new UiChartMarker { Visible = true, Width = 10, Height = 10 } },
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "x", YName = "y1", Name = "England", Marker = new UiChartMarker { Visible = true, Width = 10, Height = 10 } }
}
}) },
new UiTabItem { Header = "Rich Text Editor", HtmlContent = Html.UiRichTextEditor(new UiRichTextEditorOptions { Id = "rte", Value = "<p>The Rich Text Editor component is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content. Users can format their content using standard toolbar commands.</p>" }) },
new UiTabItem { Header = "Forms", HtmlContent = new HtmlString("<div class=\"dialog-form\"><div class=\"form-title\"><span>Add Customer Details</span></div><p><label>User Name<br /><input type=\"text\" class=\"dialog-input\" /></label></p><p><label>Date of Birth<br /><input type=\"date\" class=\"dialog-input\" /></label></p><p><label>Address<br /><textarea rows=\"2\" class=\"dialog-input\"></textarea></label></p><p><button type=\"submit\" class=\"ui-btn ui-btn-primary\">Add Customer</button> <button type=\"reset\" class=\"ui-btn\">Clear</button></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; }
#target { min-height: 560px; }
.dialog-agenda { margin: 0; padding: 12px 20px; }
.dialog-form { padding: 10px 16px; }
.dialog-input { width: 100%; box-sizing: border-box; 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; }
.form-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div id="target" class="control-section">
@Html.UiButton(new UiButtonOptions { Id = "normalbtn", Text = "Open" })
@Html.UiDialog(new UiDialogOptions
{
Id = "defaultDialog", Target = "target", Header = "Syncfusion Components inside Dialog", ShowCloseIcon = true, CloseOnEscape = true, Width = "720px", Animation = UiDialogAnimation.None, OnOpen = "dialogOpen", OnClose = "dialogClose",
Buttons = { new UiDialogButton { Text = "OK", IsPrimary = true }, new UiDialogButton { Text = "CANCEL" } },
Template = @<div>
@Html.UiTabs(new UiTabsOptions
{
Id = "dialogTabs",
Items = new List<UiTabItem>
{
new UiTabItem { Header = "Grid", HtmlContent = Html.UiGrid(new UiGridOptions
{
Id = "DefaultFunctionalities", Data = (List<LayoutDemoController.DialogOrder>)ViewData["DataSource"], AllowPaging = true,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "OrderID", HeaderText = "Order ID", Type = UiColumnType.Number, IsPrimaryKey = true, Width = 100 },
new UiGridColumn { Field = "CustomerID", HeaderText = "Customer Name", Width = 150 },
new UiGridColumn { Field = "Freight", HeaderText = "Freight", Type = UiColumnType.Number, Format = "N2", Width = 110 },
new UiGridColumn { Field = "ShipCountry", HeaderText = "Ship Country", Width = 140 }
}
}) },
new UiTabItem { Header = "Scheduler", HtmlContent = new HtmlString("<ul class=\"dialog-agenda\"><li><b>Meeting</b> 10:00 – 11:30</li><li><b>Lunch</b> 12:30 – 13:30</li><li><b>Review</b> 15:00 – 16:00</li></ul>") },
new UiTabItem { Header = "Chart", HtmlContent = Html.UiChart(new UiChartOptions
{
Id = "chart", Data = (IEnumerable<object>)ViewData["ChartData"], Title = "Inflation - Consumer Price",
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { Minimum = 0, Maximum = 100, Interval = 20, LabelFormat = "{value}%" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "x", YName = "y", Name = "Germany", Marker = new UiChartMarker { Visible = true, Width = 10, Height = 10 } },
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "x", YName = "y1", Name = "England", Marker = new UiChartMarker { Visible = true, Width = 10, Height = 10 } }
}
}) },
new UiTabItem { Header = "Rich Text Editor", HtmlContent = Html.UiRichTextEditor(new UiRichTextEditorOptions { Id = "rte", Value = "<p>The Rich Text Editor component is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content. Users can format their content using standard toolbar commands.</p>" }) },
new UiTabItem { Header = "Forms", HtmlContent = new HtmlString("<div class=\"dialog-form\"><div class=\"form-title\"><span>Add Customer Details</span></div><p><label>User Name<br /><input type=\"text\" class=\"dialog-input\" /></label></p><p><label>Date of Birth<br /><input type=\"date\" class=\"dialog-input\" /></label></p><p><label>Address<br /><textarea rows=\"2\" class=\"dialog-input\"></textarea></label></p><p><button type=\"submit\" class=\"ui-btn ui-btn-primary\">Add Customer</button> <button type=\"reset\" class=\"ui-btn\">Clear</button></p></div>") }
}
})
</div>
})
</div>
<script>
// Syncfusion: the Open button is hidden while the dialog is open
function dialogOpen() { document.getElementById('normalbtn').style.display = 'none'; }
function dialogClose() { document.getElementById('normalbtn').style.display = 'inline-block'; }
document.addEventListener('click', function (e) { if (e.target.closest('#normalbtn')) { window.Lumen.get("defaultDialog").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/ComponentsDialog.cshtml; it draws what ViewData holds.
public ActionResult ComponentsDialog()
{
ViewData["DataSource"] = new List<DialogOrder>
{
new DialogOrder { OrderID = 10248, CustomerID = "VINET", Freight = 32.38, ShipCountry = "France" },
new DialogOrder { OrderID = 10249, CustomerID = "TOMSP", Freight = 11.61, ShipCountry = "Germany" },
new DialogOrder { OrderID = 10250, CustomerID = "HANAR", Freight = 65.83, ShipCountry = "Brazil" },
new DialogOrder { OrderID = 10251, CustomerID = "VICTE", Freight = 41.34, ShipCountry = "France" },
new DialogOrder { OrderID = 10252, CustomerID = "SUPRD", Freight = 51.3, ShipCountry = "Belgium" }
};
ViewData["ChartData"] = new List<DialogInflation>
{
new DialogInflation { x = "2005", y = 21, y1 = 28 },
new DialogInflation { x = "2006", y = 24, y1 = 44 },
new DialogInflation { x = "2007", y = 36, y1 = 48 },
new DialogInflation { x = "2008", y = 38, y1 = 50 },
new DialogInflation { x = "2009", y = 54, y1 = 66 },
new DialogInflation { x = "2010", y = 57, y1 = 78 },
new DialogInflation { x = "2011", y = 70, y1 = 84 }
};
return View();
}
/// <summary>An order of the Components inside Dialog sample's grid.</summary>
public class DialogOrder
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
public double Freight { get; set; }
public string ShipCountry { get; set; }
}
/// <summary>A point of the Components inside Dialog sample's chart.</summary>
public class DialogInflation
{
public string x { get; set; }
public double y { get; set; }
public double y1 { get; set; }
}
}
}
@* 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>
Since the dialog is container component, you can integrate other UI components within the dialog. The dialog can be rendered with simple plain-text, HTML string, or UI components. In the above sample, we have used major components such as Grid, Schedule, Chart, and Rich Text Editor inside dialog.