OrchardCMS-未以编程方式将内容字段添加到自定义内容类型
通过迁移创建新的内容类型,添加到him内容字段中,但它们不会显示在仪表板中 仪表板中的内容类型视图: 我的代码怎么了OrchardCMS-未以编程方式将内容字段添加到自定义内容类型,orchardcms,orchardcms-1.10,Orchardcms,Orchardcms 1.10,通过迁移创建新的内容类型,添加到him内容字段中,但它们不会显示在仪表板中 仪表板中的内容类型视图: 我的代码怎么了 public int UpdateFrom2() { var name = "ProductViaCode"; ContentDefinitionManager.AlterPartDefinition( string.Format("{0}Part", name), b =>
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;
}
正如@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));
正如@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));
您似乎忘记了将
ProductViaCodePart
添加到您的类型中。您似乎忘记了将ProductViaCodePart
添加到您的类型中。