Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以返回视图中给定页面下方的节点级别总数?可以循环遍历子节点(例如:子节点部分),但是是否可以获得子节点的总数?
获得第一级很简单:
var naviLevel = CurrentPage.Children.Where("Visible").First().Level;
是否可以计算所有级别而不必通过剩余的子页面@foreach?
请试试这个......
@{ 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> }