我正在从ContentItem中检索完整的分类术语列表,执行以下操作:
var product = Services.ContentManager.Get<ContentItem>(33);
foreach (var term in product.TermsPart.Terms.Where(x => x.Field == "MyIndex"))
{
...
}
有人可以帮助我吗?
我读到它是可能的,使用动态来做到这一点:
dynamic product = Services.ContentManager.Get<ContentItem>(33);
foreach (var term in product.MyIndex.Terms)
{
...
}
但我找不到合适的语法!
答案 0 :(得分:3)
最好的方法是使用ITaxonomyService(http://orchardtaxonomies.codeplex.com/SourceControl/latest#Services/ITaxonomyService.cs)
将它注入到类的构造函数中(控制器,依赖项或其他):
//Note that I didn't try this code
public SomeController(ITaxonomyService taxonomyService){
var product = Services.ContentManager.Get<ContentItem>(33);
var terms = taxonomyService.GetTermsForContentItem(product.Id); //Or just 33
}