【发布时间】:2015-08-31 19:56:35
【问题描述】:
我想使用 Umbraco Forms 不仅可以插入数据,还可以对其进行编辑。到目前为止,当我想编辑一条记录时,我正在通过查询字符串传递表单 guid 和记录 id,并在字段中填充正确的数据。 到目前为止一切顺利。
然后我像这样成功连接到 Umbraco.Forms.Data.Storage.RecordStorage.RecordInserting 事件
void RecordStorage_RecordInserting(object sender, Umbraco.Forms.Core.RecordEventArgs e)
{
var ms = (Umbraco.Forms.Data.Storage.RecordStorage)sender;
if(this record exists){
ms.UpdateRecord(e.Record, e.Form);
}
}
但是,当我尝试提交已编辑的记录并运行 ms.RecordUpdate(e.Record, e.Form) 行时,我收到此错误
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UFRecordDataString_UFRecordFields_Key". The conflict occurred in database "UmbracoPlay", table "dbo.UFRecordFields", column 'Key'.
The statement has been terminated.
我不能删除旧记录然后插入新记录,因为每次我调用 ms.InsertRecord 时它都会重新引发相同的事件
我错过了什么? 如何使用 Umbraco Forms 编辑现有数据?
【问题讨论】:
-
如果您正在编辑数据,我认为您不需要挂钩插入事件。您使用的是哪个版本的 Umbraco/Contour?
标签: umbraco umbraco7 umbraco-contour