我似乎无法将附加数据存储在附加到用户的单独内容部分中。我做了以下事情:
- 创建了一个模块
- 在模块中,我为 ProfilePart 和 ProfilePartRecord 创建了一个模型
- 在迁移中,我为 ProfilePartRecord 创建了一个表(来自 ContentPartRecord 类型)
- 在迁移中,我通过设置 WithPart ProfilePart 更改了 User 的类型定义
- 我创建了一个驱动程序类,它有 2 种编辑方法,一种用于获取,一种用于发布(代码片段如下
- 我还创建了一个处理程序,为 ProfilePartRecord 类型的 profilePartRepository 添加存储过滤器
模块结构
- 驱动程序/ProfilePartDriver.cs
- 处理程序/ProfileHandler.cs
- 模型/ProfilePart.cs
- 模型/ProfilePartRecord.cs
- 视图/EditorTemplates/Parts/profile.cshtml
- 迁移.cs
- 安置信息
因为我认为问题出在驱动程序中。这是我的代码:
是否因为部件附加到用户而出错?还是我错过了其他东西。
公共类 ProfilePartDriver:ContentPartDriver {
protected override string Prefix
{
get { return "Profile"; }
}
//GET
protected override DriverResult Editor(ProfilePart part, dynamic shapeHelper)
{
return ContentShape("Parts_Profile_Edit", () =>
shapeHelper.EditorTemplate(TemplateName: "Parts/Profile", Model: part, Prefix: Prefix));
}
//POST
protected override DriverResult Editor(ProfilePart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}