2016-09-19 118 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