Class Breadcrumb
- Namespace
- Cuemon.AspNetCore.Mvc
- Assembly
- Cuemon.AspNetCore.Mvc.dll
Represents a breadcrumb that can be used for navigation purposes on a website.
public class Breadcrumb
- Inheritance
-
Breadcrumb
Examples
The following example demonstrates how to use to build navigation breadcrumbs for an MVC application.
using System;
using System.Collections.Generic;
using Cuemon.AspNetCore.Mvc;
namespace MyApp.Examples;
public class BreadcrumbExample
{
public void Demonstrate()
{
// Build a breadcrumb trail for a product detail page
var breadcrumbs = new List<Breadcrumb>
{
new() { Label = "Home", ControllerName = "Home", ActionName = "Index" },
new() { Label = "Products", ControllerName = "Product", ActionName = "Index" },
new() { Label = "Electronics", ControllerName = "Product", ActionName = "Category" },
new() { Label = "Smartphone X", ControllerName = "Product", ActionName = "Details" }
};
// Render breadcrumb items
foreach (var crumb in breadcrumbs)
{
Console.WriteLine($"<a href='/{crumb.ControllerName}/{crumb.ActionName}'>{crumb.Label}</a>");
// Output:
// <a href='/Home/Index'>Home</a>
// <a href='/Product/Index'>Products</a>
// <a href='/Product/Category'>Electronics</a>
// <a href='/Product/Details'>Smartphone X</a>
// The last breadcrumb typically represents the current page (no link)
var current = breadcrumbs[^1];
Console.WriteLine($"<span>{current.Label}</span>");
// Output: <span>Smartphone X</span>
}}
}
Properties
ActionName
Gets or sets the name of the action that this breadcrumb represents.
public string ActionName { get; set; }
Property Value
- string
The name of the action that this breadcrumb represents.
ControllerName
Gets or sets the name of the controller this breadcrumb is associated with.
public string ControllerName { get; set; }
Property Value
- string
The name of the controller this breadcrumb is associated with.
Label
Gets or sets the label of the breadcrumb.
public string Label { get; set; }
Property Value
- string
The label of the breadcrumb.