Reputation: 21
Is it possible to return the total number of node levels beneath a given page in a view? It's possible loop through the child nodes (ex: the descendants partial), but is it possible to get the total child levels?
Getting the first level is simple:
var naviLevel = CurrentPage.Children.Where("Visible").First().Level;
Is it possible to count all levels without having to @foreach through the remaining child pages?
Upvotes: 0
Views: 925
Reputation: 231
Please try this......
@{
var list = new List<int>();
var currentPage = Model;
foreach (var child in currentPage.Descendants())
{
int level = Convert.ToInt32(child.Level);
list.Add(level);
}
var levelCount = list.Distinct().Max();
<h2>@levelCount</h2>
}
Upvotes: 1