Example of Accordion Navigation Menu in ASP.NET MVC Splitter Control
This example demonstrates the Accordion control that can be integrated within the split pane. Select the product from the left pane to display the corresponding product details on the right pane.
ASP.NET
- Grid
- Schedule
- Chart
ASP.NET MVC
- Grid
- Schedule
- Chart
JavaScript
- Grid
- Schedule
- Chart
Select an item of the menu.
@Html.UiSplitter(new UiSplitterOptions
{
Id = "splitter-accordin", Height = "288px", Width = "100%",
Panes =
{
new UiSplitterPane
{
Size = "39%", Min = "30%",
HtmlContent = Html.UiAccordion(new UiAccordionOptions
{
Id = "Accordion_default",
Items = ((List<LayoutDemoController.SplitterAccordionItem>)ViewData["AccordionItems"]).Select(item => new UiAccordionItem
{
Header = item.Header, Expanded = item.Expanded,
HtmlContent = Html.UiListView(new UiListViewOptions { Id = "nested_" + item.Folder, OnSelect = "onselect", Items = item.Pages.Select(page => new UiListItem(item.Folder + "-" + page.ToLower(), page)).ToList() })
}).ToList()
})
},
new UiSplitterPane { Size = "65%", Min = "45%", Template = @<div id="content" class="content">Select an item of the menu.</div> }
}
})
<style>
.control-section { padding: 10px 15px; }
.content { padding: 10px 12px; font-size: 14px; }
.content > a { font-weight: 600; }
#pane-heading { margin: 0 0 6px; font-weight: 600; }
#panetext { font-size: 13px; color: var(--ui-muted); }
.control_wrapper { max-width: 900px; margin: 0 auto; }
#content h4 { margin-top: 0; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div id="target">
@Html.UiSplitter(new UiSplitterOptions
{
Id = "splitter-accordin", Height = "288px", Width = "100%",
Panes =
{
new UiSplitterPane
{
Size = "39%", Min = "30%",
HtmlContent = Html.UiAccordion(new UiAccordionOptions
{
Id = "Accordion_default",
Items = ((List<LayoutDemoController.SplitterAccordionItem>)ViewData["AccordionItems"]).Select(item => new UiAccordionItem
{
Header = item.Header, Expanded = item.Expanded,
HtmlContent = Html.UiListView(new UiListViewOptions { Id = "nested_" + item.Folder, OnSelect = "onselect", Items = item.Pages.Select(page => new UiListItem(item.Folder + "-" + page.ToLower(), page)).ToList() })
}).ToList()
})
},
new UiSplitterPane { Size = "65%", Min = "45%", Template = @<div id="content" class="content">Select an item of the menu.</div> }
}
})
</div>
</div>
<script>
// Syncfusion: selecting an item of a nested list reads its details into the right pane
function onselect(args) {
var file = args.item.value;
fetch('@Url.Content("~/Content/splitter/")' + file + '-ajax.html').then(function (response) { return response.text(); }).then(function (html) {
document.getElementById('content').innerHTML = html;
});
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class SplitterController : Controller
{
// The page is Views/Splitter/AccordionNavigationMenu.cshtml; it draws what ViewData holds.
public ActionResult AccordionNavigationMenu()
{
ViewData["AccordionItems"] = new List<SplitterAccordionItem>
{
new SplitterAccordionItem { Header = "ASP.NET", Folder = "aspnet", Expanded = true, Pages = new List<string> { "Grid", "Schedule", "Chart" } },
new SplitterAccordionItem { Header = "ASP.NET MVC", Folder = "aspnetmvc", Expanded = false, Pages = new List<string> { "Grid", "Schedule", "Chart" } },
new SplitterAccordionItem { Header = "JavaScript", Folder = "javascript", Expanded = false, Pages = new List<string> { "Grid", "Schedule", "Chart" } }
};
return View();
}
/// <summary>An item of the Accordion Navigation Menu sample: its header and the pages of the list it holds.</summary>
public class SplitterAccordionItem
{
public string Header { get; set; }
public string Folder { get; set; }
public bool Expanded { get; set; }
public List<string> Pages { 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>
The Splitter is the layout user interface (UI) control and allows integrating other JavaScript UI controls within its pane. In this sample, the Splitter control is used to design navigation menu-like application using JavaScript Accordion control. The Accordion control is integrated within left pane to display the product menu and selected product details on right pane.