Getting Started with the Stepper
This tutorial explains how to set up a basic Telerik UI for ASP.NET MVC Stepper and highlights the major steps in the configuration of the component.
You will initialize a Stepper control with predefined items and icons. Next, you will handle some of the Stepper events.
Prerequisites
To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET MVC components:
To create a new pre-configured project for the Telerik UI for ASP.NET MVC components, you can use a project template.
To manually configure an existing project by using NuGet, see the Adding Telerik UI through NuGet.
1. Prepare the CSHTML File
The first step is to add the required directives at the top of the .cshtml
document:
-
To use the Telerik UI for ASP.NET MVC HtmlHelpers:
@using Kendo.Mvc.UI
Optionally, you can structure the document by adding the desired HTML elements like headings, divs, paragraphs, and apply some basic styles.
2. Initialize the Stepper
Use the Stepper HtmlHelper to add the component to a page:
The
Name()
configuration method is mandatory as its value is used for theid
of the Stepper element.The
Items()
configuration method lets you add the desired Stepper items.The
Icon()
option of the Stepper individual items can be used to set the desired icon for the step.
@using Kendo.Mvc.UI
@(Html.Kendo().Stepper()
.Name("stepper")
.Steps(s =>
{
s.Add().Label("Home").Icon("home");
s.Add().Label("Settings").Icon("gear");
s.Add().Label("Attachments").Icon("paperclip");
s.Add().Label("Save").Icon("save");
})
)
4. Handle the Stepper Events
The Stepper exposes various events that you can handle and further customize the functionality of the component. In this tutorial, you will use the Activate
and Select
events of the Stepper.
@using Kendo.Mvc.UI
@(Html.Kendo().Stepper()
.Name("stepper")
.Steps(s =>
{
s.Add().Label("Home").Icon("home");
s.Add().Label("Settings").Icon("gear");
s.Add().Label("Attachments").Icon("paperclip");
s.Add().Label("Save").Icon("save");
})
.Events(events => events.Activate("onActivate").Select("onSelect"))
)
<script>
function onActivate(e) {
console.log("Activated: " + e.step.options.label);
}
function onSelect(e) {
console.log("Selected: " + e.step.options.label);
}
</script>
For more examples, refer to the demo on using the events of the Stepper.
5. (Optional) Reference Existing Stepper Instances
To use the client-side API of the Stepper and build on top of its initial configuration, you need a reference to the Stepper instance. Once you get a valid reference, you can call the respective API methods:
-
Use the
.Name()
(id attribute) of the component instance to get a reference.<script> var stepperReference = $("#Stepper").data("kendoStepper"); // stepperReference is a reference to the existing instance of the helper. </script>
-
Use the Stepper client-side API to control the behavior of the widget. In this example, you will use the
next
method to selects the step which is immediately after the currently selected step.<script> $(document).ready(function () { var stepperReference = $("#Stepper").data("kendoStepper"); stepperReference.next(); }) </script>
For more information on referencing specific helper instances, see the Methods and Events article.