在 SurfaceController 中创建 NestedContent 项 [英] Create NestedContent Items In SurfaceController

查看:17
本文介绍了在 SurfaceController 中创建 NestedContent 项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种文档类型:

  1. 表单提交
  2. 表单域

Form 文档类型有一个名为 Fields 的属性,它是一个 嵌套内容 包含 FormField 文档类型列表的数据类型.我正在尝试以编程方式(在 SurfaceController 中)创建一个 FormField 并将其添加到 Form 文档类型的 Fields 属性.

The Form document type has a property named Fields which is a Nested Content data type that contains a list of FormField document types. I am trying to programmatically (in a SurfaceController) create a FormField and add it to the Fields property of the Form document type.

这是我尝试使用的代码:

Here is the code I am trying to use to do this:

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); 行它抛出这个异常:

On the newFormSubmission.SetValue("fields", newFormFields); line it throws this exception:

'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' 的最佳重载方法匹配有一些无效参数

The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments

任何人都知道如何在 嵌套内容数据类型?

Anyone have any ideas how to store a list of DocumentTypes in the Nested Content data type?

PS:我使用的是 Umbraco 7.4.0 版程序集:1.0.5885.31226

Lee Kelleher 为我指明了在 这个在 umbraco 表格上发布.我希望在这个项目之后有时间来完善我的解决方案并向项目提交拉取请求.

Lee Kelleher pointed me in the right direction towards developing my own solution in this post on the umbraco forms. I hope to have time after this project to polish up my solution and submit a pull request to the project.

我基本上最终创建了一些扩展方法,这些方法采用 IEnumerable 并返回 NestedContent 插件.

I basically ended up creating some extension methods that take an IEnumerable<IContent> and return a JSON representation of the objects for the NestedContent plugin.

推荐答案

这个要点可能对你有帮助:

This gist might help you:

robertjf/NestedContentCreator.cs

下面的第二个文件中有一个示例.它是去年写的,可能需要一些调整;但它应该给你一个好的开始.

There's an example in the second file further down. It was written last year and may require some tweaking; but it should give you a good start.

这篇关于在 SurfaceController 中创建 NestedContent 项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆