Search results

Data binding in ASP.NET MVC Breadcrumb control

03 Dec 2021 / 2 minutes to read

Items based on current Url

The Breadcrumb items can be generated from the current URL of the page, if the url property was not provided or when the user does not specify the breadcrumb items using the BreadcrumbItemDirective tag. The following example shows the breadcrumb items that are generated based on the current URL.

razor
Copied to clipboard
@Html.EJS().Breadcrumb("default")..EnableNavigation(false).Render()

Output be like the below.

Breadcrumb Sample

This output screenshot shows the Bind to Location sample. This sample is hosted in different location, so the breadcrumb is rendered with different location instead of the actual location.

Static URL

The Breadcrumb items can be generated by providing the url property in the component, if the user does not specify the breadcrumb items using the BreadcrumbItemDirective tag. The following example shows the breadcrumb items generated from the provided url in the component.

razor
default.cs
Copied to clipboard
@Html.EJS().Breadcrumb("url").EnableNavigation(false).Url("https://ej2.syncfusion.com/aspnetmvc/Breadcrumb/DefaultFunctionalities").Render()
Copied to clipboard
public ActionResult Index()
{
    return View();
}

Output be like the below.

Breadcrumb Sample

Customize text when generated items using Url

The Breadcrumb items text can be customized by using the beforeItemRender event. In the following example, All Components text was customized as Components.

razor
default.cs
Copied to clipboard
@Html.EJS().Breadcrumb("url").EnableNavigation(false).BeforeItemRender("beforeItemRender").Url("https://ej2.syncfusion.com/aspnetmvc/Breadcrumb/BindToLocation").Render()
    
<script>
    function beforeItemRender(args) {
        if (args.item.text === 'BindToLocation') {
            args.item.text = 'location';
        }
    }
</script>
Copied to clipboard
public ActionResult Index()
{
    return View();
}

Output be like the below.

Breadcrumb Sample