Table of Contents

Class NavigationTreeViewModel

Namespace
Dynamicweb.Frontend.Navigation
Assembly
Dynamicweb.dll

Represents a navigation tree for use in a rendering context.

public class NavigationTreeViewModel : ViewModelBase
Inheritance
NavigationTreeViewModel
Inherited Members

Examples

Using the viewmodel in a razor template.

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.Navigation.NavigationTreeViewModel>

<div>@{RenderNodes(Model.Nodes);}</div>

@functions { 
 void RenderNodes(IEnumerable<Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel> nodes)
 {
	 <ul>
		 @foreach(var node in nodes)
		 {
			 <li>
				 <a href="@node.Link">@node.Name</a>
				 @{RenderNodes(node.Nodes);}
			 </li>
		 }
	 </ul>
 }
}

Properties

ActiveNode

Gets the active node of the current navigation - the node whose children are being displayed in Nodes.

public NavigationTreeNodeViewModel ActiveNode { get; }

Property Value

NavigationTreeNodeViewModel

A NavigationTreeNodeViewModel representing the current node.

Remarks

For Subnodes, this is the deepest active node found during traversal, with correct Name, Link, and GroupId.

For all other expand modes, this is the tree root node.

This can be used to render a back button or a header for the current level of navigation.

Nodes

Gets the sub nodes (children) to the root node.

public IEnumerable<NavigationTreeNodeViewModel> Nodes { get; }

Property Value

IEnumerable<NavigationTreeNodeViewModel>

A collection of NavigationTreeNodeViewModel

Parameters

Gets the custom parameters.

Custom parameters can be set through Parameters and then they can be used in the template that renders the navigation.

public IDictionary<string, object?> Parameters { get; }

Property Value

IDictionary<string, object>

The parameters as an IDictionary<TKey, TValue> where TKey and TValue are both string.

To top