在foreach中通过Alias过滤Umbraco动态变量

时间:2016-09-21 08:57:11

标签: c# linq razor umbraco

我试图通过Alias过滤动态变量,并想知道这是否可行,就像我写一个lamba表达式一样,例如

foreach (var item in node.Children.Where(x => x.NodeTypeAlias != "ContentContainer"))

这会导致错误 - 使用lambda表达式作为动态调度操作的参数,而无需先将其转换为delagate或表达式树类型。

请有人帮助我。

  if (sub.NodeTypeAlias == "MenuExternalLink")
        {
            UrlPickerState urlPicker = UrlPickerState.Deserialize(sub.GetPropertyValue("LinkURL"));
            subUrl = urlPicker.Url;
            subTarget = urlPicker.NewWindow ? "_blank" : "";


            //get root home page node
            var homePage = CurrentModel.AncestorsOrSelf(1).First();
            //get the node under the homepage where the node name matches the redirect (MenuExternalLink) node name
            var menuNode = homePage.Children.Where(x => x.NodeTypeAlias == "NormalTextPage" && x.Name.Contains(sub.Name) && x.GetPropertyValue("umbracoNaviHide") != "1");
            //get the nodes under menuNode

            foreach (var q in menuNode)
            {
                //we have the id of the node so get the child nodes based on that id
                var node = Library.NodeById(q.Id);

                foreach (var item in node.Children.Where("NodeTypeAlias == \"NormalTextPage\""))
                {

                    <li ><a href="@item.Url" >@item.Name</a></li>

                }

            }


        }

0 个答案:

没有答案