# Getting Started with the Breadcrumb

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

You will initialize a Breadcrumb control, configure its icons, and handle its events. Finally, you can run the sample code in [Telerik REPL](https://netcorerepl.telerik.com/) and continue exploring the components.

![Sample Telerik UI for ASP.NET Core Breadcrumb](https://www.telerik.com/aspnet-core-ui/documentation/assets/3bbd5f69cc4ea42929afe7358b51ac79/breadcrumb-getting-started.png)

## 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](https://netcorerepl.telerik.com/) 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](https://www.telerik.com/aspnet-core-ui/documentation/vs-integration/new-project-wizard).

## 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:

  ```cshtml
  @using Kendo.Mvc.UI
  ```

* To use the Telerik UI for ASP.NET Core TagHelpers:

  ```cshtml
  @addTagHelper *, Kendo.Mvc
  ```

## 2. Initialize the Breadcrumb

Use the Breadcrumb 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 Breadcrumb element.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    @(Html.Kendo().Breadcrumb()
            .Name("breadcrumb")
    )
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <kendo-breadcrumb name="breadcrumb"> 
    </kendo-breadcrumb>
```

## 3. Add Breadcrumb Items

The next step is to use the `Items()` configuration and add the [Breadcrumb items](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/breadcrumb/items). To configure the items:

1. Use the `Type()` property to define the type of the added item—`RootItem` or `Item`.

2. Use the `Text()` property to define the textual content for the Breadcrumb item.

3. Use the `Href()` property to set the navigation URL of the item.

4. Use the `ShowText()` property to render the textual content for the `RootItem`:

   * The default value for `RootItem` is `false`.
   * The default value for `Item` is `true`.

```Razor HtmlHelper
    @(Html.Kendo().Breadcrumb()
            .Name("breadcrumb")
            .Items(items =>
            {
                items.Add()
                        .Type(BreadcrumbItemType.RootItem)
                        .Href("https://demos.telerik.com/aspnet-core/")
                        .Text("All Components")
                        .ShowText(true);
                items.Add()
                        .Type(BreadcrumbItemType.Item)
                        .Href("/breadcrumb")
                        .Text("Breadcrumb");
                items.Add()
                        .Type(BreadcrumbItemType.Item)
                        .Href("/events")
                        .Text("Events");
            })
    )
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <kendo-breadcrumb name="breadcrumb">
        <kendo-breadcrumb-items>
            <kendo-breadcrumb-item type="BreadcrumbItemType.RootItem" text="All Components" href="https://demos.telerik.com/aspnet-core/" show-text="true" ></kendo-breadcrumb-item>
            <kendo-breadcrumb-item type="BreadcrumbItemType.Item" text="Breadcrumb" href="/breadcrumb"></kendo-breadcrumb-item>
            <kendo-breadcrumb-item type="BreadcrumbItemType.Item" text="Events" href="/events"></kendo-breadcrumb-item>
        </kendo-breadcrumb-items>
    </kendo-breadcrumb>
```

## 4. Add Icons

You can configure the [icons for the Breadcrumb items](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/breadcrumb/icons) by using the `Icon()` property. By default, the Breadcrumb renders an icon only for the `RootItem` type. To display icons for the `Item` type, set the `ShowIcon()` property to `true`. Additionally, you can also change the [icons that separate the Breadcrumb items](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/breadcrumb/icons#delimiter-icon).

```Razor HtmlHelper
    @(Html.Kendo().Breadcrumb()
            .Name("breadcrumb")
            .Items(items =>
            {
                items.Add()
                        .Type(BreadcrumbItemType.RootItem)
                        .Href("https://demos.telerik.com/aspnet-core/")
                        .Text("All Components")
                        .ShowText(true)
                        .Icon("globe");
                items.Add()
                        .Type(BreadcrumbItemType.Item)
                        .Href("/breadcrumb")
                        .Text("Breadcrumb")
                        .Icon("gear")
                        .ShowIcon(true);
                items.Add()
                        .Type(BreadcrumbItemType.Item)
                        .Href("/events")
                        .Text("Events")
                        .Icon("cloud")
                        .ShowIcon(true);
            })
    )
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <kendo-breadcrumb name="breadcrumb">
        <kendo-breadcrumb-items>
            <kendo-breadcrumb-item type="BreadcrumbItemType.RootItem" text="All Components" href="https://demos.telerik.com/aspnet-core/" show-text="true" icon="globe"></kendo-breadcrumb-item>
            <kendo-breadcrumb-item type="BreadcrumbItemType.Item" text="Breadcrumb" href="/breadcrumb" icon="gear" show-icon="true"></kendo-breadcrumb-item>
            <kendo-breadcrumb-item type="BreadcrumbItemType.Item" text="Events" href="/events" icon="cloud" show-icon="true"></kendo-breadcrumb-item>
        </kendo-breadcrumb-items>
</kendo-breadcrumb>
```

## 5. Handle Breadcrumb Events

The Breadcrumb component exposes the `Change()` and `Click()` events that you can handle and further customize the functionality of the component.

```Razor HtmlHelper
    @(Html.Kendo().Breadcrumb()
            .Name("breadcrumb")
            .Events(e => 
                e.Click("onClick")
                .Change("onChange"))
            .Items(items =>
            {
                items.Add()
                        .Type(BreadcrumbItemType.RootItem)
                        .Href("https://demos.telerik.com/aspnet-core/")
                        .Text("All Components")
                        .ShowText(true)
                        .Icon("globe");
                items.Add()
                        .Type(BreadcrumbItemType.Item)
                        .Href("/breadcrumb")
                        .Text("Breadcrumb")
                        .Icon("gear")
                        .ShowIcon(true);
                items.Add()
                        .Type(BreadcrumbItemType.Item)
                        .Href("/events")
                        .Text("Events")
                        .Icon("cloud")
                        .ShowIcon(true);
            })
    )

    <script>
        function onClick(e) {
            console.log("Clicked. :: target: " + e.item.text + ". Type :: " + e.item.type);
        }
        function onChange(e) {
            console.log("Changed. New Value :: " + e.value);
        }
    </script>
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <kendo-breadcrumb name="breadcrumb"
        on-change="onChange"
        on-click="onClick">
        <kendo-breadcrumb-items>
            <kendo-breadcrumb-item type="BreadcrumbItemType.RootItem" text="All Components" href="https://demos.telerik.com/aspnet-core/" show-text="true" icon="globe"></kendo-breadcrumb-item>
            <kendo-breadcrumb-item type="BreadcrumbItemType.Item" text="Breadcrumb" href="/breadcrumb" icon="gear" show-icon="true"></kendo-breadcrumb-item>
            <kendo-breadcrumb-item type="BreadcrumbItemType.Item" text="Events" href="/events" icon="cloud" show-icon="true"></kendo-breadcrumb-item>
        </kendo-breadcrumb-items>
    </kendo-breadcrumb>

    <script>
        function onClick(e) {
            console.log("Clicked. :: target: " + e.item.text + ". Type :: " + e.item.type);
        }
        function onChange(e) {
            console.log("Changed. New Value :: " + e.value);
        }
    </script>
```

For more examples, refer to the [demo on using the events of the Breadcrumb](https://demos.telerik.com/aspnet-core/breadcrumb/events).

## 6. (Optional) Reference Existing Breadcrumb Instances

You can reference the Breadcrumb 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.

   ```JS script
   <script>
       var breadcrumbReference = $("#breadcrumb").data("kendoBreadcrumb"); // breadcrumbReference is a reference to the existing instance of the helper.
   </script>
   ```

2. Use the [Breadcrumb client-side API](https://docs.telerik.com/kendo-ui/api/ui/breadcrumb#methods) to control the behavior of the widget. In this example, you will use the `value` method to change Breadcrumb value.

   ```JS script
   <script>
       var breadcrumbReference = $("#breadcrumb").data("kendoBreadcrumb"); // breadcrumbReference is a reference to the existing instance of the helper.
       breadcrumbReference.value("All Components/Breadcrumb/API"); // Set a new value for the component.
   </script>
   ```

For more information on referencing specific helper instances, see the [Methods and Events](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/helper-basics/events-and-methods) article.

## Explore this Tutorial in REPL

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

* [Sample code with the Breadcrumb HtmlHelper](https://netcorerepl.telerik.com/GQbbEwby24x18ZLm09)
* [Sample code with the Breadcrumb TagHelper](https://netcorerepl.telerik.com/mcFFucPo24jGi9nR25)

## Next Steps

* [Configure Editing of the Breadcrumb Path](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/breadcrumb/editing)
* [Configure the Breadcrumb Navigation](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/breadcrumb/navigation)

## See Also

* [Using the API of the Breadcrumb for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/breadcrumb/api)
* [Breadcrumb Client-Side API](https://docs.telerik.com/kendo-ui/api/ui/breadcrumb)
* [Server-Side API of the Breadcrumb](https://www.telerik.com/aspnet-core-ui/documentation/api/breadcrumb)
* [Knowledge Base Section](https://www.telerik.com/aspnet-core-ui/documentation/knowledge-base)
