2016-09-19 83 views
0

通過遷移創建新的內容類型,添加到他的內容字段,但它們不顯示在儀表板中。在儀表板OrchardCMS-未添加內容字段以自定義內容類型編程

內容類型的看法:

enter image description here

有什麼錯我的代碼?

public int UpdateFrom2() { 

     var name = "ProductViaCode"; 
     ContentDefinitionManager.AlterPartDefinition(
      string.Format("{0}Part", name), 
       b => b 
        .Attachable() 
        .WithField("ProductId", cfg => cfg 
         .OfType("InputField") 
         .WithDisplayName("Product Id"))); 

     ContentDefinitionManager.AlterTypeDefinition(
      name, cfg => cfg 
      .WithPart(typeof(CommonPart).Name) 
      .WithPart(typeof(AutoroutePart).Name) 
      .WithPart(typeof(BodyPart).Name) 
      .WithPart(typeof(TitlePart).Name) 
      .WithPart(typeof(MenuPart).Name) 
      .Creatable() 
      .Draftable() 
      .Listable() 
      .Securable()); 

     return 3; 
    } 
+1

看來您已經忘記將您的ProductViaCodePart添加到您的類型中。 – Xceno

回答

2

正如@Xceno所說,您沒有將該部分添加到您的內容類型中。但是,通過這樣做,它不會顯示在「字段」部分下,但在「零件」部分下的「ProductViaCode」下顯示。這是因爲你用'Part'作爲後綴。

使其出現下的類型的「字段」部分中,您可以將字段添加到類型的相同名稱的部分,則該部分添加到您的類型:

var name = "ProductViaCode"; 
    ContentDefinitionManager.AlterPartDefinition(

     // Without 'Part' postfix 
     name, 
      b => b 
       .Attachable() 
       .WithField("ProductId", cfg => cfg 
        .OfType("InputField") 
        .WithDisplayName("Product Id"))); 

// Don't forget to add the part to the type 
ContentDefinitionManager.AlterTypeDefinition(name, cfg => cfg 

    .WithPart(name)); 
+0

非常感謝!它爲我工作:) – Ievgen

相關問題