Example of Wizard in ASP.NET MVC Tabs Control
This sample demonstrates simple train reservation wizard that enable/disable Tab items based on sequential validation of each Tab content.
Plan your journey
Select the train from the list
| Train No | Name | Departure | Arrival | Availability |
|---|
Enter the passenger details
| Name | Age | Gender | Berth Preference |
|---|---|---|---|
Confirm your booking
| Train No | Name | Gender | Berth |
|---|
@Html.UiTabs(new UiTabsOptions
{
Id = "wizardTab",
Items = new List<UiTabItem>
{
new UiTabItem
{
Header = "New Booking",
Template = @<div id="booking">
<div class="wizard-title">Plan your journey</div>
<div class="search-row">
<div class="search-item">@Html.UiDropDownList("startPoint", new UiDropDownListOptions { Placeholder = "From", Width = "100%", Items = cities.Select(c => new UiListItem(c.Name, c.Name)).ToList() })</div>
<div class="search-item">@Html.UiDropDownList("endPoint", new UiDropDownListOptions { Placeholder = "To", Width = "100%", Items = cities.Select(c => new UiListItem(c.Name, c.Name)).ToList() })</div>
</div>
<div class="search-row">
<div class="search-item">@Html.UiDatePicker("date", new UiDatePickerOptions { Placeholder = "Journey Date", Width = "100%" })</div>
<div class="search-item">@Html.UiDropDownList("quota", new UiDropDownListOptions { Placeholder = "Ticket type", Width = "100%", Items = quota.Select(q => new UiListItem(q, q)).ToList() })</div>
</div>
<div class="btn-container"><button type="button" id="searchNext" class="ui-btn">Search Train</button></div>
<span id="err1"></span>
</div>
},
new UiTabItem
{
Header = "Train List",
Disabled = true,
Template = @<div id="selectTrain">
<div class="wizard-title">Select the train from the list </div>
<table class="wizard-table" id="availableTrain">
<thead><tr><th>Train No</th><th>Name</th><th>Departure</th><th>Arrival</th><th>Availability</th></tr></thead>
<tbody></tbody>
</table>
<br />
<div class="btn-container">
<button type="button" id="goToSearch" class="ui-btn">Back</button>
<button type="button" id="bookTickets" class="ui-btn">Continue</button>
</div>
<span id="err2"></span>
</div>
},
new UiTabItem
{
Header = "Add Passenger",
Disabled = true,
Template = @<div id="details">
<div class="details-page wizard-title">Enter the passenger details</div>
<table class="wizard-table" id="passenger-table">
<thead><tr><th class="name-header">Name</th><th class="age-header">Age</th><th class="gender-header">Gender</th><th class="type-header">Berth Preference</th></tr></thead>
<tbody>
@for (int i = 1; i <= 3; i++)
{
<tr>
<td><input id="pass_name@(i)" class="wizard-input" type="text" placeholder="Passenger Name" /></td>
<td><input id="pass_age@(i)" class="wizard-input" type="number" min="1" max="100" value="18" /></td>
<td>@Html.UiDropDownList("pass_gender" + i, new UiDropDownListOptions { Value = "Male", Items = gender.Select(g => new UiListItem(g, g)).ToList() })</td>
<td>@Html.UiDropDownList("pass_berth" + i, new UiDropDownListOptions { Placeholder = "Optional", Items = berth.Select(b => new UiListItem(b, b)).ToList() })</td>
</tr>
}
</tbody>
</table>
<br />
<div class="btn-container">
<button type="button" id="goToTrains" class="ui-btn">Back</button>
<button type="button" id="goToPayment" class="ui-btn">Continue</button>
</div>
<span id="err3"></span>
</div>
},
new UiTabItem
{
Header = "Make Payment",
Disabled = true,
Template = @<div id="confirm">
<div class="wizard-title">Confirm your booking</div>
<table class="wizard-table" id="ticketgrid">
<thead><tr><th>Train No</th><th>Name</th><th>Gender</th><th>Berth</th></tr></thead>
<tbody></tbody>
</table>
<div id="fareLine"></div>
<div class="btn-container">
<button type="button" id="goToDetails" class="ui-btn">Back</button>
<button type="button" id="payNow" class="ui-btn">Pay</button>
</div>
<div id="paid"></div>
</div>
}
}
})
@Html.UiDropDownList("startPoint", new UiDropDownListOptions { Placeholder = "From", Width = "100%", Items = cities.Select(c => new UiListItem(c.Name, c.Name)).ToList() })
@Html.UiDropDownList("endPoint", new UiDropDownListOptions { Placeholder = "To", Width = "100%", Items = cities.Select(c => new UiListItem(c.Name, c.Name)).ToList() })
@Html.UiDatePicker("date", new UiDatePickerOptions { Placeholder = "Journey Date", Width = "100%" })
@Html.UiDropDownList("quota", new UiDropDownListOptions { Placeholder = "Ticket type", Width = "100%", Items = quota.Select(q => new UiListItem(q, q)).ToList() })
@Html.UiDropDownList("pass_gender" + i, new UiDropDownListOptions { Value = "Male", Items = gender.Select(g => new UiListItem(g, g)).ToList() })
@Html.UiDropDownList("pass_berth" + i, new UiDropDownListOptions { Placeholder = "Optional", Items = berth.Select(b => new UiListItem(b, b)).ToList() })
<style>
.e-tab-section, .control-section .e-sample-resize-container { max-width: 760px; margin: 0 auto; padding-top: 20px; }
.wizard-title { font-size: 16px; font-weight: 600; text-align: center; margin: 10px 0 16px; }
.search-row { display: flex; gap: 16px; margin-bottom: 16px; }
.search-item { flex: 1; }
.btn-container { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }
.wizard-table { width: 100%; border-collapse: collapse; }
.wizard-table th, .wizard-table td { padding: 6px 8px; border-bottom: 1px solid #ddd; text-align: left; }
#availableTrain tbody tr { cursor: pointer; }
#availableTrain tbody tr:hover { background: #f3f2f1; }
#availableTrain tbody tr.selected { background: #dbeaf7; }
.wizard-input { width: 100%; box-sizing: border-box; padding: 5px 8px; border: 1px solid #c8c8c8; border-radius: 4px; }
#err1, #err2, #err3 { display: block; text-align: center; color: #c62828; margin-top: 8px; }
#fareLine { margin: 12px 0; font-weight: 600; }
#paid { margin-top: 12px; color: #2e7d32; font-weight: 600; text-align: center; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
@{
var cities = (List<NavigationDemoController.CitiesFields>)ViewData["citiesData"];
var quota = (string[])ViewData["quota"];
var gender = (string[])ViewData["gender"];
var berth = (string[])ViewData["berth"];
}
<div class="control-section e-tab-section">
<div class="e-sample-resize-container">
@Html.UiTabs(new UiTabsOptions
{
Id = "wizardTab",
Items = new List<UiTabItem>
{
new UiTabItem
{
Header = "New Booking",
Template = @<div id="booking">
<div class="wizard-title">Plan your journey</div>
<div class="search-row">
<div class="search-item">@Html.UiDropDownList("startPoint", new UiDropDownListOptions { Placeholder = "From", Width = "100%", Items = cities.Select(c => new UiListItem(c.Name, c.Name)).ToList() })</div>
<div class="search-item">@Html.UiDropDownList("endPoint", new UiDropDownListOptions { Placeholder = "To", Width = "100%", Items = cities.Select(c => new UiListItem(c.Name, c.Name)).ToList() })</div>
</div>
<div class="search-row">
<div class="search-item">@Html.UiDatePicker("date", new UiDatePickerOptions { Placeholder = "Journey Date", Width = "100%" })</div>
<div class="search-item">@Html.UiDropDownList("quota", new UiDropDownListOptions { Placeholder = "Ticket type", Width = "100%", Items = quota.Select(q => new UiListItem(q, q)).ToList() })</div>
</div>
<div class="btn-container"><button type="button" id="searchNext" class="ui-btn">Search Train</button></div>
<span id="err1"></span>
</div>
},
new UiTabItem
{
Header = "Train List",
Disabled = true,
Template = @<div id="selectTrain">
<div class="wizard-title">Select the train from the list </div>
<table class="wizard-table" id="availableTrain">
<thead><tr><th>Train No</th><th>Name</th><th>Departure</th><th>Arrival</th><th>Availability</th></tr></thead>
<tbody></tbody>
</table>
<br />
<div class="btn-container">
<button type="button" id="goToSearch" class="ui-btn">Back</button>
<button type="button" id="bookTickets" class="ui-btn">Continue</button>
</div>
<span id="err2"></span>
</div>
},
new UiTabItem
{
Header = "Add Passenger",
Disabled = true,
Template = @<div id="details">
<div class="details-page wizard-title">Enter the passenger details</div>
<table class="wizard-table" id="passenger-table">
<thead><tr><th class="name-header">Name</th><th class="age-header">Age</th><th class="gender-header">Gender</th><th class="type-header">Berth Preference</th></tr></thead>
<tbody>
@for (int i = 1; i <= 3; i++)
{
<tr>
<td><input id="pass_name@(i)" class="wizard-input" type="text" placeholder="Passenger Name" /></td>
<td><input id="pass_age@(i)" class="wizard-input" type="number" min="1" max="100" value="18" /></td>
<td>@Html.UiDropDownList("pass_gender" + i, new UiDropDownListOptions { Value = "Male", Items = gender.Select(g => new UiListItem(g, g)).ToList() })</td>
<td>@Html.UiDropDownList("pass_berth" + i, new UiDropDownListOptions { Placeholder = "Optional", Items = berth.Select(b => new UiListItem(b, b)).ToList() })</td>
</tr>
}
</tbody>
</table>
<br />
<div class="btn-container">
<button type="button" id="goToTrains" class="ui-btn">Back</button>
<button type="button" id="goToPayment" class="ui-btn">Continue</button>
</div>
<span id="err3"></span>
</div>
},
new UiTabItem
{
Header = "Make Payment",
Disabled = true,
Template = @<div id="confirm">
<div class="wizard-title">Confirm your booking</div>
<table class="wizard-table" id="ticketgrid">
<thead><tr><th>Train No</th><th>Name</th><th>Gender</th><th>Berth</th></tr></thead>
<tbody></tbody>
</table>
<div id="fareLine"></div>
<div class="btn-container">
<button type="button" id="goToDetails" class="ui-btn">Back</button>
<button type="button" id="payNow" class="ui-btn">Pay</button>
</div>
<div id="paid"></div>
</div>
}
}
})
</div>
</div>
<script>
var wizard;
var fares = {};
@foreach (var c in cities) { <text>fares[@Html.Raw(Json.Encode(c.Name))] = @c.Fare;</text> }
var selectedTrain = null;
var trains = [];
window.addEventListener('load', function () {
wizard = window.Lumen.get('wizardTab');
// the journey date starts today and can be three months ahead, as in Syncfusion's sample
window.Lumen.get('date').setValue(new Date());
document.getElementById('searchNext').addEventListener('click', searchTrains);
document.getElementById('goToSearch').addEventListener('click', function () { wizard.select(0); });
document.getElementById('bookTickets').addEventListener('click', chooseTrain);
document.getElementById('goToTrains').addEventListener('click', function () { wizard.select(1); });
document.getElementById('goToPayment').addEventListener('click', addPassengers);
document.getElementById('goToDetails').addEventListener('click', function () { wizard.select(2); });
document.getElementById('payNow').addEventListener('click', function () {
document.getElementById('paid').textContent = 'Payment received. Have a nice journey!';
});
document.querySelector('#availableTrain tbody').addEventListener('click', function (e) {
var row = e.target.closest('tr');
if (!row) { return; }
Array.prototype.forEach.call(document.querySelectorAll('#availableTrain tbody tr'), function (r) { r.classList.remove('selected'); });
row.classList.add('selected');
selectedTrain = trains[Number(row.getAttribute('data-index'))];
});
});
function say(id, text) { document.getElementById(id).textContent = text; }
// Search Train: the two cities must differ; the trains between them are listed
function searchTrains() {
var from = window.Lumen.get('startPoint').getValue();
var to = window.Lumen.get('endPoint').getValue();
say('err1', '');
if (!from || !to) { say('err1', 'Choose the cities of your journey.'); return; }
if (from === to) { say('err1', 'The two cities must be different.'); return; }
trains = [];
for (var i = 0; i < 5; i++) {
trains.push({ TrainNo: 12001 + i * 7, Name: from + ' - ' + to + ' Express ' + (i + 1), Departure: (6 + i * 3) + ':00', Arrival: (10 + i * 3) + ':30', Availability: 40 - i * 7 });
}
document.querySelector('#availableTrain tbody').innerHTML = trains.map(function (t, i) {
return '<tr data-index="' + i + '"><td>' + t.TrainNo + '</td><td>' + t.Name + '</td><td>' + t.Departure + '</td><td>' + t.Arrival + '</td><td>' + t.Availability + '</td></tr>';
}).join('');
selectedTrain = null;
wizard.enableTab(1, true);
wizard.select(1);
}
function chooseTrain() {
say('err2', '');
if (!selectedTrain) { say('err2', 'Select a train from the list.'); return; }
wizard.enableTab(2, true);
wizard.select(2);
}
function addPassengers() {
say('err3', '');
var rows = [];
for (var i = 1; i <= 3; i++) {
var name = document.getElementById('pass_name' + i).value.trim();
if (name) { rows.push({ name: name, gender: window.Lumen.get('pass_gender' + i).getValue() || '', berth: window.Lumen.get('pass_berth' + i).getValue() || '' }); }
}
if (!rows.length) { say('err3', 'Enter the name of at least one passenger.'); return; }
document.querySelector('#ticketgrid tbody').innerHTML = rows.map(function (r) {
return '<tr><td>' + selectedTrain.TrainNo + '</td><td>' + r.name.replace(/</g, '<') + '</td><td>' + r.gender + '</td><td>' + r.berth + '</td></tr>';
}).join('');
var fare = (fares[window.Lumen.get('startPoint').getValue()] || 0) + (fares[window.Lumen.get('endPoint').getValue()] || 0);
say('fareLine', 'Total fare: $' + (fare * rows.length) + ' for ' + rows.length + ' passenger(s)');
document.getElementById('paid').textContent = '';
wizard.enableTab(3, true);
wizard.select(3);
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TabController : Controller
{
// The page is Views/Tab/Wizard.cshtml; it draws what ViewData holds.
public ActionResult Wizard()
{
ViewData["quota"] = new string[] { "Business Class", "Economy Class", "Common Class" };
ViewData["gender"] = new string[] { "Male", "Female" };
ViewData["berth"] = new string[] { "Upper", "Lower", "Middle", "Window", "Aisle" };
ViewData["citiesData"] = new List<CitiesFields>
{
new CitiesFields { Name = "Chicago", Fare = 300 },
new CitiesFields { Name = "San Francisco", Fare = 125 },
new CitiesFields { Name = "Los Angeles", Fare = 175 },
new CitiesFields { Name = "Seattle", Fare = 250 },
new CitiesFields { Name = "Florida", Fare = 150 }
};
ViewData["min"] = DateTime.Now;
ViewData["max"] = DateTime.Now.AddMonths(3);
return View();
}
/// <summary>A city of the Wizard sample and the fare to or from it.</summary>
public class CitiesFields
{
public string Name { get; set; }
public int Fare { 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>
Tab items can be disabled dynamically by passing the index and boolean value to the enableTab method.
You can design wizard like sample with Tab using the in-built API and customizing the content with proper validations.