2016-02-29 77 views
0

在Umbraco 7解决方案中,我在所有页面上都有一个Tags内容选择器。页面可以用这个,在每个页面上设置标签。查找标签页

然后,我想要在包装网站中获取包含标签111(id,not name)的alle页面。

我曾尝试用:

var ids = Model.MacroParameters["tags"]; //the tags to show 
CurrentPage.AncestorOrSelf(1).Descendants().Where(x => ids.Contains(x.tags.ToString())); 

但是,这给我的错误:

Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type 

请告诉我正确的方法是什么?

回答

1

解决了;

Umbraco.Content(rootId).Descendants().Where("tags.Contains(@0)", ids); 
1

根据您喜欢动态还是强类型视图模型,您有几个选项。

强类型的API

Umbraco.TypedContentAtRoot().Descendants().Where(x => x.tags.Contains(ids)); 

动态API

Umbraco.ContentAtRoot().Descendants().Where("tags.Contains(@0)", ids); 

请注意:包含声明可能会给你不一致的结果,因为标签属性似乎是返回一个逗号分隔的列表。在这种情况下,您可以尝试拆分字符串或安装Core Property Value Converters package并获取标签IEnumerable<IPublishedContent>

0

总是尽量避免使用Descendants,特别是在根节点上。 要获取标签的属性:

ApplicationContext.Current.Services.TagService.GetTagsForProperty(Model.Content.Id, "propertyname") 

要找到一个特定的标签内容:

ApplicationContext.Current.Services.TagService.GetTaggedContentByTag("tag")