Example of Bind to Location in ASP.NET MVC Breadcrumb Control
This sample demonstrates the navigation functionality of the Breadcrumb component.
Bind to Location
URL Binding and Navigation
@Html.UiButton(new UiButtonOptions { Id = "reset", Text = "Reset State", Size = UiInputSize.Small })
@Html.UiBreadcrumb(new UiBreadcrumbOptions { Id = "bind-to-location", OnItemClick = "noNavigation", BindToLocation = true })
@Html.UiBreadcrumb(new UiBreadcrumbOptions { Id = "url-binding", Url = "https://ej2.syncfusion.com/aspnetmvc/Breadcrumb/BindToLocation", OnBeforeItemRender = "beforeItemRenderHandler" })
<style>
.content-wrapper { width: 90%; margin: 0 auto; min-width: 85px; }
.content-wrapper div.row { padding: 15px 0px; }
#reset { float: right; margin: 5px 2px 5px 0; }
.content-wrapper {
width: 90%;
margin: 0 auto;
min-width: 85px;
}
.content-wrapper div.row {
padding: 15px 0px;
}
</style>
<script>
var url = 'https://ej2.syncfusion.com/aspnetmvc/breadcrumb/bindtolocation#/bootstrap5',
themeName = url.split('/')[6];
// Syncfusion: beforeItemRender gives the items of the address their own links, and leaves the theme out
function beforeItemRenderHandler(args) {
if (args.item.text == 'aspnetmvc') {
args.item.url = args.item.url + '/grid/gridoverview#/' + themeName;
}
else if (args.item.text == 'Breadcrumb') {
args.item.url = args.item.url.toLowerCase() + '/defaultFunctionalities#/' + themeName;
}
else if (args.item.text == themeName) {
args.cancel = true;
}
}
</script>
<div class="control-section">
<div class="content-wrapper">
<div class="row material2">
<div class="col-xs-12 col-sm-12 col-lg-12 col-md-12">
<h5 style="display: inline-block">Bind to Location</h5>
@Html.UiButton(new UiButtonOptions { Id = "reset", Text = "Reset State", Size = UiInputSize.Small })
</div>
</div>
<div class="row material2">
<div class="col-xs-12 col-sm-12 col-lg-12 col-md-12">
@Html.UiBreadcrumb(new UiBreadcrumbOptions { Id = "bind-to-location", OnItemClick = "noNavigation", BindToLocation = true })
</div>
</div>
<div class="row material2">
<div class="col-xs-12 col-sm-12 col-lg-12 col-md-12">
<h5>URL Binding and Navigation</h5>
</div>
</div>
<div class="row material2">
<div class="col-xs-12 col-sm-12 col-lg-12 col-md-12">
@Html.UiBreadcrumb(new UiBreadcrumbOptions { Id = "url-binding", Url = "https://ej2.syncfusion.com/aspnetmvc/Breadcrumb/BindToLocation", OnBeforeItemRender = "beforeItemRenderHandler" })
</div>
</div>
</div>
</div>
<script>
// Syncfusion: Reset State sets every Breadcrumb of the page back as it was first drawn
document.getElementById('reset').addEventListener('click', function () {
document.querySelectorAll('.content-wrapper .ui-breadcrumb').forEach(function (breadcrumb) { window.Lumen.get(breadcrumb.id).reset(); });
});
// Syncfusion: enableNavigation is false, so a click on an item only raises the event
function noNavigation() { return false; }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class BreadcrumbController : Controller
{
// The page is Views/Breadcrumb/BindToLocation.cshtml; it draws what ViewData holds.
public ActionResult BindToLocation()
{
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Breadcrumb component can be rendered by using the href(URL) of the current page or by using url property when the user is not specified the breadcrumb items using items property. In this demonstration, URL navigation is enabled URL Binding and Navigation and beforeItemRender event is used to customize rendering Breadcrumb item.