在 SurfaceController 中创建 NestedContent 项
Create NestedContent Items In SurfaceController
我有两种文档类型:
- 表单提交
- 表单域
Form 文档类型有一个名为 Fields 的 属性,它是一个 Nested Content 包含 FormField 文档类型列表的数据类型。我正在尝试以编程方式(在 SurfaceController 中)创建一个 FormField 并将其添加到 的 Fields 属性 ]表格文件类型。
这是我尝试使用的代码:
var newFormFields = new List<Umbraco.Core.Models.IContent>();
int i = 0;
foreach (var formField in model.Fields)
{
string fieldName = string.Format("Field {0}", i);
var newFormField = contentService.CreateContent(fieldName, newFormSubmission.Id, "formFieldSubmission", formNode.CreatorId);
newFormField.SetValue("fieldName", formField.Name);
newFormField.SetValue("fieldType", formField.Type);
newFormField.SetValue("manditory", formField.Manditory);
newFormField.SetValue("fieldValue", formField.Value);
newFormFields.Add(newFormField);
++i;
}
newFormSubmission.SetValue("fields", newFormFields);
var status = contentService.SaveAndPublishWithStatus(newFormSubmission, formNode.CreatorId, raiseEvents: false);
在 newFormSubmission.SetValue("fields", newFormFields);
行抛出异常:
The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments
有人知道如何在 Nested Content 数据类型中存储文档类型列表吗?
PS: 我正在使用 Umbraco 版本 7.4.0 程序集:1.0.5885.31226
更新:
Lee Kelleher pointed me in the right direction towards developing my own solution in this post on the umbraco forms。我希望在这个项目之后有时间完善我的解决方案并向项目提交拉取请求。
我基本上最终创建了一些扩展方法,这些方法采用 IEnumerable<IContent>
和 return JSON 表示 NestedContent plugin 的对象。
似乎 SetPropertyValue
方法的第二个参数需要 string
而你传递的是 List<Umbraco.Core.Models.IContent>
这条要点可能对您有所帮助:
robertjf/NestedContentCreator.cs
下面的第二个文件中有一个示例。它是去年写的,可能需要一些调整;但它应该会给你一个好的开始。
我有两种文档类型:
- 表单提交
- 表单域
Form 文档类型有一个名为 Fields 的 属性,它是一个 Nested Content 包含 FormField 文档类型列表的数据类型。我正在尝试以编程方式(在 SurfaceController 中)创建一个 FormField 并将其添加到 的 Fields 属性 ]表格文件类型。
这是我尝试使用的代码:
var newFormFields = new List<Umbraco.Core.Models.IContent>();
int i = 0;
foreach (var formField in model.Fields)
{
string fieldName = string.Format("Field {0}", i);
var newFormField = contentService.CreateContent(fieldName, newFormSubmission.Id, "formFieldSubmission", formNode.CreatorId);
newFormField.SetValue("fieldName", formField.Name);
newFormField.SetValue("fieldType", formField.Type);
newFormField.SetValue("manditory", formField.Manditory);
newFormField.SetValue("fieldValue", formField.Value);
newFormFields.Add(newFormField);
++i;
}
newFormSubmission.SetValue("fields", newFormFields);
var status = contentService.SaveAndPublishWithStatus(newFormSubmission, formNode.CreatorId, raiseEvents: false);
在 newFormSubmission.SetValue("fields", newFormFields);
行抛出异常:
The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments
有人知道如何在 Nested Content 数据类型中存储文档类型列表吗?
PS: 我正在使用 Umbraco 版本 7.4.0 程序集:1.0.5885.31226
更新:
Lee Kelleher pointed me in the right direction towards developing my own solution in this post on the umbraco forms。我希望在这个项目之后有时间完善我的解决方案并向项目提交拉取请求。
我基本上最终创建了一些扩展方法,这些方法采用 IEnumerable<IContent>
和 return JSON 表示 NestedContent plugin 的对象。
似乎 SetPropertyValue
方法的第二个参数需要 string
而你传递的是 List<Umbraco.Core.Models.IContent>
这条要点可能对您有所帮助:
robertjf/NestedContentCreator.cs
下面的第二个文件中有一个示例。它是去年写的,可能需要一些调整;但它应该会给你一个好的开始。