Skip to content

3. Pages

Haytam Zanid edited this page Apr 17, 2019 · 2 revisions

Whenever you have a page that you want to include in your breadcrumbs, you'll have to annotate it with the Breadcrumb attribute.

Use the default page as the parent

If your page is a child of the default page, all you need to do is specify the tilte:

Razor Page

[Breadcrumb("About Me")]
public class AboutModel : PageModel
{
   ...
}

MVC Action

[Breadcrumb("About Me")]
public IActionResult About()
{
   ...
}

MVC Controller

// If the title is empty, "Home" will be used.
// The default action is "Index", it can be changed
// in the BreadcrumbOptions
[Breadcrumb("")]
public class HomeController
{
    // ...
}

Use a Razor page as the parent

If your page is a child of a Razor Page, you'll have to specify it in the FromPage property:

Razor Page

[Breadcrumb("Contact Me", FromPage = typeof(AboutModel))]
public class ContactModel : PageModel
{
   ...
}

MVC Action

[Breadcrumb("Contact Me", FromPage = typeof(AboutModel))]
public IActionResult Contact()
{
   ...
}

Use an MVC action as the parent

If your page is a child of an MVC page, you'll have to specify it in the FromAction and FromController properties:

Razor Page

[Breadcrumb("Contact Me", FromAction = "Contact", FromController = typeof(HomeController))]
public class ContactModel : PageModel
{
   ...
}

MVC Action

[Breadcrumb("Contact Me", FromAction = "Contact", FromController = typeof(HomeController))]
public IActionResult Contact()
{
   ...
}

If the FromPage is in the same Controller as the action you're annotating, you can avoid specifying the FromController property, as SmartBreadcrumbs can infer it from the class type:

public class HomeController()
{

	[DefaultBreadcrumb("My Home Page")]
	public IActionResult Index()
	{
		return View();
	}

	[DefaultBreadcrumb("About Me")]
	public IActionResult About()
	{
		return View();
	}

	// Here, the HomeController will be used as the FromController
	[DefaultBreadcrumb("Contact Me", FromAction = "About")]
	public IActionResult Contact()
	{
		return View();
	}

}
Clone this wiki locally