简体   繁体   English

对象不包含“跳过” Umbraco剃刀的定义

[英]object does not contain a definition for 'Skip' Umbraco razor

I'm trying to sort some nodes by their first letter, and page them in razor.(Umbraco). 我正在尝试按其首字母对某些节点进行排序,并用剃刀将其分页。(Umbraco)。 But get a "object does not contain a definition for 'Skip'" error when it hits the foreach. 但是,在碰到foreach时,出现“对象不包含'Skip'的定义”错误。

pagesToList = homeNode.Children.OrderBy("Name");

IEnumerable<DynamicNode> nl = @homeNode.Children.Items;
pagesToList = nl.Where(x => x.Name.StartsWith(currentLetter));

This is what @pagesToList outputs: 这是@pagesToList输出:

System.Linq.Enumerable+WhereListIterator`1[umbraco.MacroEngines.DynamicNode]


foreach(dynamic item in pagesToList.Skip(1){

}

You are possibly using the wrong property. 您可能使用了错误的属性。 If you are only after those nodes just below your homeNode , then don't use the Items property. 如果仅在homeNode下方的那些节点之后,则不要使用Items属性。 Also, try not to cast your objects. 另外,请尽量不要投射对象。 C# has an effective var object. C#有一个有效的var对象。 Assuming that homeNode is a DynamicNode, then it might be worth trying the following: 假设homeNode是DynamicNode,则可能值得尝试以下操作:

pagesToList = homeNode.Children.OrderBy("Name").Where(x => x.Name.StartsWith(currentLetter));

Then your code should work. 然后您的代码应该工作了。 Please note that again we are using var because we want the object declared at compile-time, instead of using dynamic, we should only really do when we are accessing some unknown, or dynamic , properties the pagesToList object): 请注意,我们再次使用var是因为我们希望在编译时声明对象,而不是使用dynamic,只有在访问pagesToList对象的某些未知或dynamic属性时,才应该这样做:

foreach(var item in pagesToList.Skip(1)){

}

So to summarise, it looks like your code was using the property "Items", which gave us an array of DynamicNode[] instead of an IEnumerable object. 综上所述,您的代码似乎使用的是“ Items”属性,该属性为我们提供了DynamicNode []数组,而不是IEnumerable对象。

I hope this helps you out. 我希望这能够帮到你。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM