【问题标题】:Content Part not displayed on editing view内容部分未显示在编辑视图上
【发布时间】:2023-03-10 02:36:01
【问题描述】:

我创建了一个内容部分并将其添加到内容类型。数据库是使用正确的字段创建的,但是当我想创建该类型的内容项时,不会显示字段。
我的视图名为 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>

【问题讨论】:

  • 你能指定你是如何创建内容类型的吗?它不在迁移中,所以我假设它来自管理员。
  • 是的,完全正确。我应该通过迁移来创建它吗?
  • 如果那是你想要做的,当然,但你不必这样做,它最终不应该有所作为。该类型有哪些部分(请给出确切名称)?
  • 类型有:common, Deposit Part Record, Title

标签: c# orchardcms


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    相关资源
    最近更新 更多