编辑视图中未显示内容部分

本文关键字:容部 显示 视图 编辑 | 更新日期: 2023-09-27 18:17:55

我创建了一个内容部分,并将其添加到一个内容类型中。数据库是用正确的字段创建的,但是当我想要创建该类型的内容项时,字段没有显示。
我的视图名为Deposit。cshtml,位于Views/EditorTemplates/Parts/Deposit.cshtml
我已经看到了日志文件,但是没有错误。
我尝试调试DepositPartDriver文件,但是这个类从来没有被调用过。

DepositPart.cs:

public class DepositPart : ContentPart<DepositPartRecord>
{
    public string Name
    {
        get { return Record.Name; }
        set { Record.Name = value; }
    }
    public string Currency
    {
        get { return Record.Currency; }
        set { Record.Currency = value; }
    }
    public virtual decimal Liquidity
    {
        get { return Record.Liquidity; }
        set { Record.Liquidity = value; }
    }
    public virtual int Month
    {
        get { return Record.Month; }
        set { Record.Month = value; }
    }
    public virtual string Url
    {
        get { return Record.Url; }
        set { Record.Url = value; }
    }
}
public class DepositPartRecord : ContentPartRecord
{
    public virtual string Name { get; set; }
    public virtual string Currency { get; set; }
    public virtual decimal Liquidity { get; set; }
    public virtual int Month { get; set; }
    public virtual string Url { get; set; }
}

Migrations.cs:

public class Migrations : DataMigrationImpl
{
    public int Create()
    {
        SchemaBuilder.CreateTable("DepositPartRecord", table => table
            .ContentPartRecord()
            .Column<string>("name", column => column.WithLength(50))
            .Column<string>("currency", column => column.WithLength(50))
            .Column<decimal>("liquidity")
            .Column<int>("month")
            .Column<string>("url", column => column.WithLength(50))
        );
        return 1;
    }
    public int UpdateFrom1()
    {
        ContentDefinitionManager.AlterPartDefinition("DepositPartRecord", part => part
            .Attachable());
        return 2;
    }
}

DepositPartHandler.cs:

public class DepositPartHandler : ContentHandler
{
    public DepositPartHandler(IRepository<DepositPartRecord> repository)
    {
        Filters.Add(StorageFilter.For(repository));
    }
}

DepositPartDriver.cs:

public class DepositPartDriver : ContentPartDriver<DepositPart>
{
    protected override string Prefix
    {
        get { return "Deposit"; }
    }
    protected override DriverResult Display(DepositPart part, string displayType, dynamic shapeHelper)
    {
        return ContentShape("Parts_Deposit", () => shapeHelper.Parts_Deposit());
    }
    protected override DriverResult Editor(DepositPart part, dynamic shapeHelper)
    {
        return ContentShape("Parts_Deposit_Edit", () => shapeHelper
            .EditorTemplate(TemplateName: "Parts/Deposit", Model: part, Prefix: Prefix));
    }
    protected override DriverResult Editor(DepositPart part, IUpdateModel updater, dynamic shapeHelper)
    {
        updater.TryUpdateModel(part, Prefix, null, null);
        return Editor(part, shapeHelper);
    }
}

Placement.info

<Placement>
  <Place Parts_Deposit="Content:1"/>
  <Place Parts_Deposit_Edit="Content:2"/>
</Placement>

编辑视图中未显示内容部分

我发现了我的错误,在Migration.cs上应该是:

public int UpdateFrom1()
{
    ContentDefinitionManager.AlterPartDefinition("DepositPart", part => part
        .Attachable());
    return 2;
}