Umbraco 查找带有标记的页面

Umbraco 查找带有标记的页面,umbraco,umbraco7,Umbraco,Umbraco7,在Umbraco 7解决方案中,我在所有页面上都有一个标签内容选择器。页面可以使用此选项,在每个页面上设置标签 然后我想得到intire站点中的所有页面,比如标签111(id,而不是名称) 我试过: var ids = Model.MacroParameters["tags"]; //the tags to show CurrentPage.AncestorOrSelf(1).Descendants().Where(x => ids.Contains(x.tags.ToString()))

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

然后我想得到intire站点中的所有页面,比如标签111(id,而不是名称)

我试过:

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
正确的方法是什么?

Umbraco.Content(rootId).Descendants().Where("tags.Contains(@0)", ids);
用计算机解决

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

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

强类型API

Umbraco.TypedContentAtRoot().Descendants().Where(x => x.tags.Contains(ids));
Umbraco.ContentAtRoot().Descendants().Where("tags.Contains(@0)", ids);
动态API

Umbraco.TypedContentAtRoot().Descendants().Where(x => x.tags.Contains(ids));
Umbraco.ContentAtRoot().Descendants().Where("tags.Contains(@0)", ids);

请注意,Contains语句可能会给出不一致的结果,因为tags属性似乎返回一个逗号分隔的列表。在这种情况下,您可以尝试拆分字符串或安装,并将标记设置为
IEnumerable

,这取决于您喜欢的是动态视图模型还是强类型视图模型

强类型API

Umbraco.TypedContentAtRoot().Descendants().Where(x => x.tags.Contains(ids));
Umbraco.ContentAtRoot().Descendants().Where("tags.Contains(@0)", ids);
动态API

Umbraco.TypedContentAtRoot().Descendants().Where(x => x.tags.Contains(ids));
Umbraco.ContentAtRoot().Descendants().Where("tags.Contains(@0)", ids);

请注意,Contains语句可能会给出不一致的结果,因为tags属性似乎返回一个逗号分隔的列表。在这种情况下,您可以尝试拆分字符串或安装,并将标记作为
IEnumerable

始终避免使用子体,尤其是在根节点上。 要获取属性的标记,请执行以下操作:

ApplicationContext.Current.Services.TagService.GetTagsForProperty(Model.Content.Id, "propertyname")
要查找具有特定标记的内容,请执行以下操作:

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

始终避免使用子体,尤其是在根节点上。 要获取属性的标记,请执行以下操作:

ApplicationContext.Current.Services.TagService.GetTagsForProperty(Model.Content.Id, "propertyname")
要查找具有特定标记的内容,请执行以下操作:

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