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; }
}
和ContentPart类:
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;
}
}
问题是当我插入小部件时,它被添加但我看不到它。为什么?
答案 0 :(得分:1)
您需要为窗口小部件添加一个Handler来保存该项目,并使用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
此外,您没有提及有驱动程序或视图,但我猜它是Handler或您缺少的展示位置信息。此外,在关联驱动程序,迁移和放置信息时,请仔细检查拼写和惯例,因为如果您手动创建零件,有几个地方可以使用错误的文本字符串。