簡體   English   中英

從Orchard中的ContentItem中檢索分類術語

[英]Retrieve taxonomy terms from ContentItem in Orchard

我想從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)
{
    ...
}

但我找不到合適的語法!

最好的方法是使用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

   }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM