# Getting Started with the Breadcrumb

This tutorial explains how to set up a basic Telerik UI for ASP.NET MVC 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.

![Sample Telerik UI for ASP.NET MVC Breadcrumb](https://www.telerik.com/aspnet-mvc/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 MVC components:

* To create a new pre-configured project for the Telerik UI for ASP.NET MVC components, you can [use a project template](https://www.telerik.com/aspnet-mvc/documentation/getting-started-mvc/first-steps).

* To manually configure an existing project by using NuGet, see the [Adding Telerik UI through NuGet](https://www.telerik.com/aspnet-mvc/documentation/getting-started/setup-with-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:

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

## 2. Initialize the Breadcrumb

Use the Breadcrumb HtmlHelper  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")
    )
```

## 3. Add Breadcrumb Items

The next step is to use the `Items()` configuration and add the [Breadcrumb items](https://www.telerik.com/aspnet-mvc/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");
            })
    )
```

## 4. Add Icons

You can configure the [icons for the Breadcrumb items](https://www.telerik.com/aspnet-mvc/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-mvc/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);
            })
    )
```

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

For more examples, refer to the [demo on using the events of the Breadcrumb](https://demos.telerik.com/aspnet-mvc/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-mvc/documentation/html-helpers/helper-basics/events-and-methods) article.

## Next Steps

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

## See Also

* [Using the API of the Breadcrumb for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/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-mvc/documentation/api/breadcrumb)
* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
