0

我有果园的问题。我创建了一个视频播放器小部件,它是一个带有 ContentPartRecord 类的简单小部件:

public class VideoPlayerPartRecord : ContentPartRecord
    {
        public virtual string MediaFile { get; set; }
        public virtual int Width { get; set; }
        public virtual int Height { get; set; }
        public virtual bool AutoStart { get; set; }
        public virtual bool Repeat { get; set; }
    }

和课程内容部分:

    public class VideoPlayerPart : ContentPart<VideoPlayerPartRecord>
        {
            [Required(ErrorMessage = "Media File required")]
            [Display(Name = "Media File: ")]
            public string MediaFile
            {
                get { return Record.MediaFile; }
                set { Record.MediaFile = value; }
            }

            [Required(ErrorMessage = "Width required")]
            [Display(Name = "Width: ")]
            public int Width
            {
                get { return Record.Width; }
                set { Record.Width = value; }
            }

            [Required(ErrorMessage = "Height required")]
            [Display(Name = "Height: ")]
            public int Height
            {
                get { return Record.Height; }
                set { Record.Height = value; }
            }

            [Display(Name = "Auto Start: ")]
            public bool AutoStart
            {
                get { return Record.AutoStart; }
                set { Record.AutoStart = value; }
            }

            [Display(Name = "Repeat: ")]
            public bool Repeat
            {
                get { return Record.Repeat; }
                set { Record.Repeat = value; }
            }
        }

这是文件迁移:

    public class Migrations : DataMigrationImpl {

            public int Create() {
                // Creating table default_Raise_VideoPlayer_VideoPlayePartRecord
                SchemaBuilder.CreateTable("default_Raise_VideoPlayer_VideoPlayePartRecord", table => table
                    .ContentPartRecord()
                    .Column("MediaFile", DbType.String)
                    .Column("Width", DbType.Int32)
                    .Column("Height", DbType.Int32)
                    .Column("AutoStart", DbType.Boolean)
                    .Column("Repeat", DbType.Boolean)
                );

                ContentDefinitionManager.AlterPartDefinition(typeof(VideoPlayerPart).Name, cfg => cfg
                    .Attachable());

                return 1;
            }

            public int UpdateFrom1() {
                ContentDefinitionManager.AlterTypeDefinition("VideoPlayerWidget", cfg => cfg
                    .WithPart("VideoPlayerPart")
                    .WithPart("WidgetPart")
                    .WithPart("CommonPart")
                    .WithSetting("Stereotype", "Widget"));

                return 2;

            }


        }

问题是当我插入小部件时,它被添加但我看不到它。为什么??

4

1 回答 1

1

您需要为您的小部件添加一个处理程序来持久化该项目,并添加一个placement.info 条目来呈现它。

http://docs.orchardproject.net/Documentation/Writing-a-content-part

(代码取自文章)

using Maps.Models;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;

namespace Maps.Handlers {
    public class MapHandler : ContentHandler {
        public MapHandler(IRepository<MapRecord> repository) {
            Filters.Add(StorageFilter.For(repository));
        }
    }
}

和 Placement.info

<Placement>
    <Place Parts_Map="Content:10"/>
    <Place Parts_Map_Edit="Content:7.5"/>
</Placement>

如果它不保存到数据库中 - 它可能是处理程序。如果它没有显示在屏幕上,可能是placement.info

此外,您没有提到有驱动程序或视图,但我猜这是您缺少的处理程序或放置信息。此外,在关联驱动程序、迁移和放置信息时,请非常仔细地检查拼写和约定,因为如果您手动创建零件,有几个地方可能会使用错误的文本字符串。

于 2013-06-05T19:28:17.150 回答