gpt4 book ai didi

asp.net-mvc - Orchard 自定义模块不保存所有项目

转载 作者:行者123 更新时间:2023-12-01 06:38:55 25 4
gpt4 key购买 nike

在 Orchard 构建我的第一个模块,除了保存(在某些字段上)之外的所有内容都在工作。我在保存时没有收到错误,这些字段只显示它们的默认值,没有在数据库表中插入/更新值。

我一开始只用一个属性构建了模块,然后在我确认管理员更新的内容后将更多属性添加到记录部分。现在新字段显示在编辑器中,但只有原始属性 (SoldOut) 在更新或创建时保存。我看到另一个帖子建议删除 mappings.bin 文件,但这并没有改变任何东西。谢谢你的帮助!

以下是主要类(class):

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 类(这样你就可以看到我的更新——这些都反射(reflect)在数据库中)
    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));
}
}

最佳答案

当然,我在发布问题 5 分钟后发现了问题。我错过了编辑器的 cshtml 文件中的一个日期时间字段,当它保存到数据库时,它在更新时死了,因为日期列不会为空。

关于asp.net-mvc - Orchard 自定义模块不保存所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12717703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com