在Orchard中构建我的第一个模块,除了保存(在某些字段上)之外的所有模块都在工作。我在保存时没有出错,这些字段只显示其默认值,而没有在数据库表中插入/更新值。
我最初只使用一个属性构建了模块,然后在我确认从管理员更新了一些内容后,将更多内容添加到了recordpart。现在,新字段显示在编辑器中,但只有原始属性(SoldOut)在更新或创建时保存。我看到另一篇建议删除mappings.bin文件的帖子,但这并没有改变任何东西。谢谢你的帮助!
以下是主要课程:
public class ConferencePartRecord : ContentPartRecord
{
public virtual bool OnlyShowTeaser { get; set; }
public virtual int TheYear { get; set; }
public virtual DateTime StartDate { get; set; }
public virtual DateTime EndDate { get; set; }
public virtual DateTime EarlyReg { get; set; }
public virtual DateTime RegularReg { get; set; }
public virtual DateTime LateReg { get; set; }
public virtual DateTime ConfirmDate { get; set; }
public virtual bool SoldOut { get; set; }
public virtual bool ConferenceSpace { get; set; }
public virtual int EarlyBirdException { get; set; }
public virtual string NextConf { get; set; }
}
public class ConferencePart : ContentPart<ConferencePartRecord>
{
public bool OnlyShowTeaser
{
get { return Record.OnlyShowTeaser; }
set { Record.OnlyShowTeaser = value; }
}
public int TheYear
{
get { return Record.TheYear; }
set { Record.TheYear = value; }
}
public DateTime StartDate
{
get { return Record.StartDate; }
set { Record.StartDate = value; }
}
public DateTime EndDate
{
get { return Record.EndDate; }
set { Record.EndDate = value; }
}
public DateTime EarlyReg
{
get { return Record.EarlyReg; }
set { Record.EarlyReg = value; }
}
public DateTime RegularReg
{
get { return Record.RegularReg; }
set { Record.RegularReg = value; }
}
public DateTime LateReg
{
get { return Record.LateReg; }
set { Record.LateReg = value; }
}
public DateTime ConfirmDate
{
get { return Record.ConfirmDate; }
set { Record.ConfirmDate = value; }
}
public bool ConferenceSpace
{
get { return Record.ConferenceSpace; }
set { Record.ConferenceSpace = value; }
}
public int EarlyBirdException
{
get { return Record.EarlyBirdException; }
set { Record.EarlyBirdException = value; }
}
public String NextConf
{
get { return Record.NextConf; }
set { Record.NextConf = value; }
}
public bool SoldOut
{
get { return Record.SoldOut; }
set { Record.SoldOut = value; }
}
}
这是我的驱动程序类:
public class ConferenceDriver : ContentPartDriver<AeriesConference.Models.ConferencePart>
{
protected override DriverResult Display(ConferencePart part, string displayType, dynamic shapeHelper)
{
return ContentShape("Parts_Conference", () => shapeHelper.Parts_Conference(SoldOut: part.SoldOut));
}
//GET
protected override DriverResult Editor(ConferencePart part, dynamic shapeHelper)
{
return ContentShape("Parts_Conference_Edit",
() => shapeHelper.EditorTemplate(
TemplateName: "Parts/Conference",
Model: part,
Prefix: Prefix));
}
//POST
protected override DriverResult Editor(ConferencePart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}
... migrations.cs类(这样你就可以看到我的更新 - 这些都反映在数据库中)
public int Create() {
// Creating table ConferenceRecord
SchemaBuilder.CreateTable("ConferencePartRecord", table => table
.ContentPartRecord()
.Column("SoldOut", DbType.Boolean)
);
return 1;
}
public int UpdateFrom1()
{
// Create (or alter) a part called "ConferencePart" and configure it to be "attachable".
ContentDefinitionManager.AlterPartDefinition("ConferencePart", part => part
.Attachable());
return 2;
}
public int UpdateFrom2()
{
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("OnlyShowTeaser", DbType.Boolean));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("TheYear", DbType.Int16));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("StartDate", DbType.DateTime));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("EndDate", DbType.DateTime));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("EarlyReg", DbType.DateTime));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("RegularReg", DbType.DateTime));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("LateReg", DbType.DateTime));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("ConfirmDate", DbType.DateTime));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("ConferenceSpace", DbType.Boolean));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("EarlyBirdException", DbType.Int16));
SchemaBuilder.AlterTable("ConferencePartRecord", table => table.AddColumn("NextConf", DbType.String));
return 3;
}
}
最后,我的处理程序类:
public class ConferencePartHandler : ContentHandler
{
public ConferencePartHandler(IRepository<ConferencePartRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
}
}
答案 0 :(得分:0)
当然,我在发布问题后5分钟发现了这个问题。我错过了编辑器的cshtml文件中的一个日期时间字段,当它保存到数据库时,由于日期列不会为空,因此它在更新时死亡。