New to Telerik UI for ASP.NET Core? Download free 30-day trial

Getting Started with the TabStrip

This tutorial explains how to set up a basic Telerik UI for ASP.NET Core TabStrip and highlights the major steps in the configuration of the component.

You will initialize a TabStrip component with several items and a basic content definition. Finally, you can run the sample code in Telerik REPL and continue exploring the components.

Sample Telerik UI for ASP.NET Core TabStrip

Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET Core components:

  • You can use the Telerik REPL playground and skip installing the components on your system and configuring a project.

  • You can prepare a Visual Studio project by following the following guide:

    • Creating a new pre-configured project for the Telerik UI for ASP.NET Core components from a project template.

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 Core HtmlHelpers:

    @using Kendo.Mvc.UI
    
  • To use the Telerik UI for ASP.NET Core TagHelpers:

    @addTagHelper *, Kendo.Mvc
    

Optionally, you can structure the document by adding the desired HTML elements like headings, divs, paragraphs, and others.

    @using Kendo.Mvc.UI

    <h4>TabStrip with cities</h4>
    <div>

    </div>
    @addTagHelper *, Kendo.Mvc

    <h4>TabStrip with cities</h4>
    <div>

    </div>

2. Initialize the TabStrip

Use the TabStrip HtmlHelper or TagHelper to add the component to a page:

  • The Name() configuration method is mandatory as its value is used for the id and the name attributes of the TabStrip element.
  • The Selected() configuration of a TabStrip's item specifies which tab is selected initially.
  • The Image() property of a TabStrip's item determines the icon or logo path in front of its text.
@using Kendo.Mvc.UI

<h4>TabStrip with cities</h4>
<div>
@(Html.Kendo().TabStrip()
    .Name("tabstrip")
    .Items(tabstrip =>
    {
        tabstrip.Add().Text("Paris")
            .Selected(true)
            .ImageUrl(Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/photo.png"))
            .Content(@<text>
            <div class="weather">
                <h2>17<span>ºC</span></h2>
                <p>Rainy weather in Paris.</p>
            </div>
            <span class="rainy"> </span>
            </text>);

        tabstrip.Add().Text("New York")
            .ImageUrl(Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/star.png"))
            .Content(@<text>
            <div class="weather">
                <h2>29<span>ºC</span></h2>
                <p>Sunny weather in New York.</p>
            </div>
            <span class="sunny"> </span>
            </text>);
    })
)
</div>
@addTagHelper *, Kendo.Mvc

<h4>TabStrip with cities</h4>
<div>
    <kendo-tabstrip name="tabstrip">
        <items>
            <tabstrip-item text="Paris" selected="true" 
            image-url="@Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/photo.png")">
                <content>
                    <div class="weather">
                        <h2>17<span>&ordm;C</span></h2>
                        <p>Rainy weather in Paris.</p>
                    </div>
                    <span class="rainy">&nbsp;</span>
                </content>
            </tabstrip-item>
            <tabstrip-item text="New York" 
            image-url="@Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/star.png")">
                <content>
                    <div class="weather">
                        <h2>29<span>&ordm;C</span></h2>
                        <p>Sunny weather in New York.</p>
                    </div>
                    <span class="sunny">&nbsp;</span>
                </content>
            </tabstrip-item>
        </items>
    </kendo-tabstrip>
</div>

3. Setting the Tab Position

The next step is to demonstrate how you can set the TabPosition() option which allows you to dictate where the tabs are rendered. The default setting is Top, but you can also use Left, Bottom, etc.

    @using Kendo.Mvc.UI

<h4>TabStrip with cities</h4>
<div>
@(Html.Kendo().TabStrip()
    .Name("tabstrip")
    .TabPosition(TabStripTabPosition.Top)
    .Items(tabstrip =>
    {
        tabstrip.Add().Text("Paris")
            .Selected(true)
            .ImageUrl(Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/photo.png"))
            .Content(@<text>
            <div class="weather">
                <h2>17<span>ºC</span></h2>
                <p>Rainy weather in Paris.</p>
            </div>
            <span class="rainy"> </span>
            </text>);

        tabstrip.Add().Text("New York")
            .ImageUrl(Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/star.png"))
            .Content(@<text>
            <div class="weather">
                <h2>29<span>ºC</span></h2>
                <p>Sunny weather in New York.</p>
            </div>
            <span class="sunny"> </span>
            </text>);
    })
)
</div>
   @addTagHelper *, Kendo.Mvc

<h4>TabStrip with cities</h4>
<div>
    <kendo-tabstrip name="tabstrip" tab-position="top">
        <items>
            <tabstrip-item text="Paris" selected="true" 
            image-url="@Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/photo.png")">
                <content>
                    <div class="weather">
                        <h2>17<span>&ordm;C</span></h2>
                        <p>Rainy weather in Paris.</p>
                    </div>
                    <span class="rainy">&nbsp;</span>
                </content>
            </tabstrip-item>
            <tabstrip-item text="New York" 
            image-url="@Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/star.png")">
                <content>
                    <div class="weather">
                        <h2>29<span>&ordm;C</span></h2>
                        <p>Sunny weather in New York.</p>
                    </div>
                    <span class="sunny">&nbsp;</span>
                </content>
            </tabstrip-item>
        </items>
    </kendo-tabstrip>
</div>

4. Handle a TabStrip Event

The TabStrip component provides convenient events for implementing your desired logic. In this tutorial, you will use the exposed Select() event to log a new entry in the browser's console.

    @using Kendo.Mvc.UI

<h4>TabStrip with cities</h4>
<div>
<script>
    function select(e) {
        console.log("Selected old value :: " + this.value());
    }
</script>

@(Html.Kendo().TabStrip()
    .Name("tabstrip")
    .TabPosition(TabStripTabPosition.Top)
    .Events(e=>e.Select("select"))
    .Items(tabstrip =>
    {
        tabstrip.Add().Text("Paris")
            .Selected(true)
            .ImageUrl(Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/photo.png"))
            .Content(@<text>
            <div class="weather">
                <h2>17<span>ºC</span></h2>
                <p>Rainy weather in Paris.</p>
            </div>
            <span class="rainy"> </span>
            </text>);

        tabstrip.Add().Text("New York")
            .ImageUrl(Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/star.png"))
            .Content(@<text>
            <div class="weather">
                <h2>29<span>ºC</span></h2>
                <p>Sunny weather in New York.</p>
            </div>
            <span class="sunny"> </span>
            </text>);
    })
)
</div>
   @addTagHelper *, Kendo.Mvc

<h4>TabStrip with cities</h4>
<div>
    <script>
    function select(e) {
        console.log("Selected old value :: " + this.value());
    }
</script>

    <kendo-tabstrip name="tabstrip" tab-position="top" on-select="select">
        <items>
            <tabstrip-item text="Paris" selected="true" 
            image-url="@Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/photo.png")">
                <content>
                    <div class="weather">
                        <h2>17<span>&ordm;C</span></h2>
                        <p>Rainy weather in Paris.</p>
                    </div>
                    <span class="rainy">&nbsp;</span>
                </content>
            </tabstrip-item>
            <tabstrip-item text="New York" 
            image-url="@Url.Content("https://demos.telerik.com/aspnet-core/shared/icons/16/star.png")">
                <content>
                    <div class="weather">
                        <h2>29<span>&ordm;C</span></h2>
                        <p>Sunny weather in New York.</p>
                    </div>
                    <span class="sunny">&nbsp;</span>
                </content>
            </tabstrip-item>
        </items>
    </kendo-tabstrip>
</div>

5. (Optional) Reference Existing TabStrip Instances

You can reference the TabStrip instances that you have created and build on top of their existing configuration:

  1. Use the id attribute of the component instance to establish a reference.

    <script>
        var tabstripReference = $("#tabstrip").data("kendoTabStrip"); // tabstripReference is a reference to the existing TabStrip instance of the helper.
    </script>
    
  2. Use the TabStrip client-side API to control the behavior of the widget. In this example, you will use the select method to select an item.

    <script>
        var tabstripReference = $("#tabstrip").data("kendoTabStrip"); // tabstripReference is a reference to the existing TabStrip instance of the helper.
        tabstripReference.select(3); 
    </script>
    

Explore this Tutorial in REPL

You can continue experimenting with the code sample above by running it in the Telerik REPL server playground:

Next Steps

See Also

In this article