Frage

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?

War es hilfreich?

Lösung

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>

 }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top