0

通过迁移创建新的内容类型,添加到他的内容字段,但它们未显示在仪表板中。

仪表板中的内容类型视图:

在此处输入图像描述

我的代码有什么问题?

    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;
    }
4

1 回答 1

2

正如@Xceno 所说,您没有将该部分添加到您的内容类型中。但是,这样做不会显示在“字段”部分下,而是显示在“零件”部分下的“ProductViaCode”下。这是因为您在它后面加上了“Part”。

要使其显示在type的“Fields”部分下,您可以将该字段添加到与该类型同名的部分,然后将该部分添加到您的类型中:

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));
于 2016-09-19T09:02:22.467 回答