EPiServer 9:EPiServer ContentArea内容有什么真正的替代品吗?

Jan*_*der 1 c# asp.net episerver

我是EPiServer的初学者.我们使用EPiServer版本9.12.EPiServer.Core.ContentArea过去有一个目录列表,现在已经过时了,请参阅:http://world.episerver.com/documentation/Class-library/?documentId = cms /7.5/2843232A

图片http://jweschenfelder.de/download/Untitled.png

内容列表在过去具有以下优点:您可以读取块的名称,因为它读取了ContentArea的完整内容.检索名称会很棒,因为如果在那里创建新块,可以在CMS中对其进行配置.如果我使用现在建议的Items集合,我无法读取包含Link items集合的块的名称,我只能读取块内的Link items集合.

我已经看到了这个例子:
IContentLoader contentLoader = ServiceLocator.Current.GetInstance< IContentLoader >(); OnSiteLinkBlock itemBlock = contentLoader.Get(item.ContentLink, new LoaderOptions() { LanguageLoaderOption.MasterLanguage() });
我能够编辑OnSiteLinkBlock,但是其他属性保持为null并且不由EPiServer的ContentLoader填充(IContentLoader是EPiServer的接口).

有关类层次结构的更多信息:
- (在EPiServer.Core中) - (BlockBase是一个自己的类) - (OnSiteLinkBlock是一个自己的类)[AvailableContentTypes(Availability = Availability.None)]
public class BlockData : ContentData, IReadOnly< BlockData >, IReadOnly

public abstract class BlockBase : BlockData
public class OnSiteLinkBlock : BlockBase

有人知道这里的解决方案吗?如何阅读ContentArea的更多属性?或者确实存在ContentArea的替代方案?非常感谢!

Eri*_*itz 5

通常,您使用ItemsFilteredItems属性从ContentAreas中读取内容.它们返回一个可枚举的ContentAreaItem.

使用解决IContent实例IContentLoader,并与喂它ContentLink

var loader = ServiceLocator.Current.GetInstance<IContentLoader>();

// contentarea is called UpperArea in the example
var icontentItems = currentPage.UpperArea
                         .FilteredItems
                         .Select(x => loader.Get<IContent>(x.ContentLink));

// example render in razor
foreach (var icontentItem in icontentItems)
{
    <h2>@icontentItem.Name</h2>
}
Run Code Online (Sandbox Code Playgroud)