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

时间:2014-08-14 12:18:59

标签: c# orchardcms

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

1 个答案:

答案 0 :(得分:0)

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

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