Skip to content

4. Manual nodes

Haytam Zanid edited this page Apr 17, 2019 · 1 revision

In the old version, you could create the breadcrumb nodes manually:

public IActionResult Action2()
{
	// Manually create the nodes (assuming you used the attribute
	// to create a Default node, otherwise create it manually too).
	var childNode1 = new BreadcrumbNode("Action 1", "Home", "Action1", null, new { id = 10 });
	
	// When manually creating nodes, you have the option to use
	// route values in case you need them
	var childNode2 = new BreadcrumbNode("Action 2", "Home", "Action2", childNode1);
	
	// All you have to do now is tell SmartBreadcrumbs about this
	ViewData["BreadcrumbNode"] = childNode2; // Use the last node
	
	return View();
}

In the current version, you can still do the same thing, except BreadcrumbNode is now abstract and you need to use on of these:

  • MvcBreadcrumbNode
  • MvcControllerBreadcrumbNode
  • RazorPageBreadcrumbNode

Example:

// If you don't create the default node manually,
// make sure it's created with an attribute as
// it will be automatically added.

/*
	Arguments:
		- string action
		- string controller
		- string title
		- bool overwriteTitleOnExactMatch = false
		- string iconClasses = null
		- string areaName = null
*/
var childNode1 = new MvcBreadcrumbNode("Action", "Controller", "Title", ...);

/*
	Arguments:
		- string controller
		- string title
		- bool overwriteTitleOnExactMatch = false
		- string iconClasses = null
		- string areaName = null
*/
var childNode2 = new MvcControllerBreadcrumbNode("Controller", "ViewData.Title")
{
	OverwriteTitleOnExactMatch = true,
	Parent = childNode1
};

/*
	Arguments:
		- string path
		- string title
		- bool overwriteTitleOnExactMatch = false
		- string iconClasses = null
		- string areaName = null
*/
var childNode3 = new RazorPageBreadcrumbNode("/Path", "ViewData.Something")
{
	OverwriteTitleOnExactMatch = true,
	Parent = childNode2
};

// Tell SmartBreadcrumbs to use them;
// PS: Use the last created node.
ViewData["BreadcrumbNode"] = childNode3;
Clone this wiki locally