0
我正在爲Orchard CMS編寫模塊,並且需要在小部件中顯示我的內容類型元素。Orchard CMS自定義小部件視圖
驅動/ FilesWidgetDriver.cs:
public class FilesWidgetPartDriver : ContentPartDriver<FilesWidgetPart>
{
private readonly IFileService _fileService;
public FilesWidgetPartDriver(IFileService fileService)
{
_fileService = fileService;
}
protected override DriverResult Display(FilesWidgetPart part, string displayType, dynamic shapeHelper)
{
return ContentShape("Parts_FilesWidget",() => shapeHelper.Parts_FilesWidget(
Files: _fileService.GetFiles()
));
}
}
型號/ FilesWidget.cs
public class FilesWidgetPart : ContentPart
{
}
查看/零件/ FilesWidget.cshtml
@using ModuleName.Models
@using Orchard.ContentManagement
@{
var files = (IContentQuery<FilePart>)Model.Files;
}
<div>
@foreach (var file in files)
{
@Html.ActionLink(file.FileName, "GetFile", "FileAdmin");
}
</div>
Migrations.cs
public int UpdateFrom1()
{
ContentDefinitionManager.AlterTypeDefinition("FilesWidget", type => type
.WithPart("FilesWidgetPart")
.WithPart("WidgetPart")
.WithSetting("Stereotype", "Widget")
);
return 2;
}
public int UpdateFrom2()
{
ContentDefinitionManager.AlterTypeDefinition("FilesWidget", type => type
.WithPart("CommonPart")
);
return 3;
}
但是,當我小工具添加到網頁,它是空的。怎麼了?謝謝!
謝謝!但我已經通過編寫動態形狀來解決這個問題:) – 2013-02-19 22:25:51