Example of API in ASP.NET MVC Timeline Control
This sample demonstrates the properties available in the Timeline control.
Travel Itenary
- Flight Booking: Reserving airline ticketsMay 13, 2024
- Hotel Accommodation: Booking lodging for the tripJune 20, 2024
- Excursion Plans: Organized visits to popular attractionsJuly 2, 2024
- Return Journey: Flight ConfirmationAug 14, 2024
Orientation
Alignment
Opposite content
Show Icon
Reverse
@Html.UiTimeline(new UiTimelineOptions { Id = "timeline", Align = UiTimelineAlign.After, Items = (List<UiTimelineItem>)ViewData["TravelItems"] })
@Html.UiDropDownList("orientation", new UiDropDownListOptions { Placeholder = "Select orientation", Width = "100%", PopupHeight = "200px", Value = "vertical", OnChange = "orientationChange", Items = ((List<string[]>)ViewData["OrientationData"]).Select(o => new UiListItem(o[1], o[0])).ToList() })
@Html.UiDropDownList("align", new UiDropDownListOptions { Placeholder = "Select alignment", Width = "100%", PopupHeight = "200px", Value = "after", Items = ((List<string[]>)ViewData["AlignData"]).Select(o => new UiListItem(o[1], o[0])).ToList(), OnChange = "alignmentChange" })
@Html.UiSwitch("showOppositeContent", true, new UiSwitchOptions { Id = "showOppositeContent", OnChange = "updateOppositeContent" })
@Html.UiSwitch("showDotCss", true, new UiSwitchOptions { Id = "showDotCss", OnChange = "updateDotCss" })
@Html.UiSwitch("reverse-timeline", false, new UiSwitchOptions { Id = "reverse-timeline", OnChange = "change" })
<style>
.timeline-api-section { height: 350px; margin-top: 20px; max-width: 700px; }
.timeline-api-section .ui-dot.e-icons { display: inline-flex; width: 32px; height: 32px; align-items: center; justify-content: center; border: 2px solid var(--ui-accent); border-radius: 50%; background: var(--ui-surface); font-size: 18px; }
.timeline-api-section .no-icons .ui-dot.e-icons::before { display: none; }
.timeline-api-section .no-icons .ui-dot.e-icons { width: 12px; height: 12px; background: var(--ui-accent); }
.timeline-api-section .no-opposite .ui-opposite-content { visibility: hidden; }
.property-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 0; }
</style>
<div class="control-section">
<div class="timeline-api-section">
<p style="font-weight: 600;"> Travel Itenary </p>
@Html.UiTimeline(new UiTimelineOptions { Id = "timeline", Align = UiTimelineAlign.After, Items = (List<UiTimelineItem>)ViewData["TravelItems"] })
</div>
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Orientation</span> @Html.UiDropDownList("orientation", new UiDropDownListOptions { Placeholder = "Select orientation", Width = "100%", PopupHeight = "200px", Value = "vertical", OnChange = "orientationChange", Items = ((List<string[]>)ViewData["OrientationData"]).Select(o => new UiListItem(o[1], o[0])).ToList() })</div>
<div class="property-row"><span>Alignment</span> @Html.UiDropDownList("align", new UiDropDownListOptions { Placeholder = "Select alignment", Width = "100%", PopupHeight = "200px", Value = "after", Items = ((List<string[]>)ViewData["AlignData"]).Select(o => new UiListItem(o[1], o[0])).ToList(), OnChange = "alignmentChange" })</div>
<div class="property-row"><span>Opposite content</span> @Html.UiSwitch("showOppositeContent", true, new UiSwitchOptions { Id = "showOppositeContent", OnChange = "updateOppositeContent" })</div>
<div class="property-row"><span>Show Icon</span> @Html.UiSwitch("showDotCss", true, new UiSwitchOptions { Id = "showDotCss", OnChange = "updateDotCss" })</div>
<div class="property-row"><span>Reverse</span> @Html.UiSwitch("reverse-timeline", false, new UiSwitchOptions { Id = "reverse-timeline", OnChange = "change" })</div>
</div>
<script>
// Syncfusion: the property panel sets orientation, align and reverse of the Timeline, and shows or hides the opposite content and the icons
function timeline() { return window.Lumen.get('timeline'); }
function orientationChange(value) { if (value) { timeline().setOrientation(value); } }
function alignmentChange(value) { if (value) { timeline().setAlign(value); } }
function change(on) { timeline().setReverse(on); }
function updateOppositeContent(on) { timeline().element.classList.toggle('no-opposite', !on); }
function updateDotCss(on) { timeline().element.classList.toggle('no-icons', !on); }
</script>
<script>
(function (window, document) {
'use strict';
function log(text) { if (window.LayoutSampleLog) { window.LayoutSampleLog(text); } }
function timeline() { return window.Lumen.get('timelineApi'); }
var steps = ['Out for delivery', 'Delivered', 'Feedback asked'];
var added = 0;
function on(id, type, handler) {
var el = document.getElementById(id);
if (el) { el.addEventListener(type, handler); }
}
on('timelineAlign', 'change', function () { timeline().setAlign(this.value); log('Align: ' + this.value + '.'); });
on('timelineOrientation', 'change', function () { timeline().setOrientation(this.value); log('Orientation: ' + this.value + '.'); });
on('timelineReverse', 'change', function () { timeline().setReverse(this.checked); log('Reverse: ' + this.checked + '.'); });
on('timelineAdd', 'click', function () {
var text = steps[added % steps.length];
added++;
timeline().addItem({ content: text, oppositeContent: (15 + added) + ':00' });
log('Added: ' + text + '.');
});
on('timelineRemove', 'click', function () { timeline().removeItem(0); log('Removed the first step.'); });
})(window, document);
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TimelineController : Controller
{
// The page is Views/Timeline/API.cshtml; it draws what ViewData holds.
public ActionResult API()
{
ViewData["TravelItems"] = new List<UiTimelineItem>
{
new UiTimelineItem { Content = "May 13, 2024", OppositeContent = "Flight Booking: Reserving airline tickets", DotCss = "e-icons e-flight" },
new UiTimelineItem { Content = "June 20, 2024", OppositeContent = "Hotel Accommodation: Booking lodging for the trip", DotCss = "e-icons e-hotel" },
new UiTimelineItem { Content = "July 2, 2024", OppositeContent = "Excursion Plans: Organized visits to popular attractions", DotCss = "e-icons e-explore" },
new UiTimelineItem { Content = "Aug 14, 2024", OppositeContent = "Return Journey: Flight Confirmation", DotCss = "e-icons e-return" }
};
ViewData["OrientationData"] = new List<string[]> { new[] { "Vertical", "vertical" }, new[] { "Horizontal", "horizontal" } };
ViewData["AlignData"] = new List<string[]> { new[] { "Before", "before" }, new[] { "After", "after" }, new[] { "Alternate", "alternate" }, new[] { "Alternate reverse", "alternatereverse" } };
return View();
}
private ActionResult Show()
{
LayoutSample sample = (LayoutSample)ViewBag.LayoutSample;
// A sample keeps its data in a Prepare<Page> method (LayoutDemoController.Samples.cs); it puts what the page reads in ViewData.
string page = sample.Source.Substring(sample.Source.LastIndexOf('_') + 1);
System.Reflection.MethodInfo prepare = GetType().GetMethod("Prepare" + page, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (prepare != null) { prepare.Invoke(this, null); }
return View("PreparedSample", ViewData.Model);
}
}
}
@* 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>
@* Layouts with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
This sample can be customized further with the combination of Timeline properties from the property pane. For example,
- The layout can be changed by selecting the orientation dropdownlist from property pane.
- Items alignment can be changed by selecting the alignment dropdownlist from property pane.
- Show or hide the information opposite to the content by toggling the opposite content switcher button.
- Show or hide the item icons by toggling the show icon switcher button.
- Reverse the timeline items by toggling the reverse switcher button.