Orchard - 以编程方式将内容项插入Content Type

时间:2015-09-01 09:47:49

标签: orchardcms

将内容项插入内容类型时遇到问题。在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);

1 个答案:

答案 0 :(得分:3)

您可能直接将字段附加到自定义" 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);