我有 ContainerWidget 和带有 ShowAllLinkCaption 字段的自定义容器类型。现在我只有一个解决方案,而且看起来很难看。在容器小部件视图上获取此字段值的正确方法是什么?
@*Latest news widget*@
@using Orchard.ContentManagement
@using Orchard.Utility.Extensions
@{
var contentId = (int)Model.ContentItem.ContainerWidgetPart.Record.ContainerId;
IContentManager contentManager = WorkContext.Resolve<IContentManager>();
var customListContentItem = contentManager.Get(contentId);
var showAllLinkCaptionField = customListContentItem.Parts.SelectMany(p => p.Fields).First(f => f.Name == "ShowAllLinkCaption");
var showAllLinkCaptionText = showAllLinkCaptionField.Storage.Get<string>(null);
}
@Display(Model.Content)
@Html.Link(showAllLinkCaptionText, Url.ItemDisplayUrl(customListContentItem))