我正在为Orchard CMS编写模块,我需要在widget中显示我的内容类型的元素。
驱动器/ 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;
}
但是当我将小部件添加到页面时,它是空的。怎么了?谢谢!
答案 0 :(得分:2)
您可能错过了展示位置。