Orchard - 以编程方式将内容项插入内容类型

Orchard - Insert content item to Content Type programmatically

我在将内容项插入内容类型时遇到问题。在 Orchard 管理中,我创建了包含以下字段的自定义内容类型:名称、姓氏、日期等...

但是我必须以编程方式在控制器方法中插入新的内容项。我试过了,但这没有用:

var item = this._services.ContentManager.New("Zadosti");
item.Name.Value = "Some dummy usage of this product"; // I can not access name field
this._services.ContentManager.Create(item);

您可能将字段直接附加到自定义 "Zadosti" 内容类型? 在这种情况下,Orchard 所做的是将字段附加到与类型完全相同的部分,它永远不会将字段附加到内容类型本身(不要让仪表板欺骗你!)

因此您可以按如下方式访问该字段:

var item = this._services.ContentManager.New("Zadosti"); 

// 'Zadosti' in here is the name of your part, which is 
// the same as your content type name
item.Zadosti.Name.Value = "Some dummy usage of this product"; 
this._services.ContentManager.Create(item);