您可以在小部件模板中执行以下操作:
@foreach (var item in Model.Items)
{
<h3 @Html.InlineEditingAttributes(Model.ProviderName, Model.ContentType.FullName, (Guid)item.Fields.Id)
@Html.InlineEditingFieldAttributes("Title", "ShortText")>
@item.Fields.Title
</h3>
<ul>
@foreach (var listItem in ((ListViewModel)item).ListItemViewModel.Items)
{
<li @Html.InlineEditingAttributes(Model.ProviderName, ((ListViewModel)item).ListItemViewModel.ContentType.FullName, (Guid)listItem.Fields.Id)>
<div @Html.InlineEditingFieldAttributes("Title", "ShortText")>
@listItem.Fields.Title
</div>
<div class="sfMultiRelatedItmsWrp">
<h2 class="sfrelatedItmTitle">Related pages</h2>
@foreach (var link in listItem.Fields.LinkedPageUrl)
{
var node = PageManager.GetManager().GetPageNode(link.Fields.Id);
var url = PageExtesnsions.GetFullUrl(node);
<div>@link.Fields.Title - @url</div>
}
</div>
</li>
}
</ul>
}
这是因为您选择了每个列表项可以选择多个页面。
编辑:确保包括以下命名空间
@model Telerik.Sitefinity.Frontend.Mvc.Models.ContentListViewModel
@using Telerik.Sitefinity.Frontend.Lists.Mvc.Models;
@using Telerik.Sitefinity.Frontend.Mvc.Helpers;
@using Telerik.Sitefinity.Modules.Pages;
EDIT2:如果自定义字段只允许选择 1 页,那么它应该如下所示:
<div class="@Model.CssClass">
@foreach (var item in Model.Items)
{
<h3 @Html.InlineEditingAttributes(Model.ProviderName, Model.ContentType.FullName, (Guid)item.Fields.Id)
@Html.InlineEditingFieldAttributes("Title", "ShortText")>
@item.Fields.Title
</h3>
<ul>
@foreach (var listItem in ((ListViewModel)item).ListItemViewModel.Items)
{
<li @Html.InlineEditingAttributes(Model.ProviderName, ((ListViewModel)item).ListItemViewModel.ContentType.FullName, (Guid)listItem.Fields.Id)>
<div @Html.InlineEditingFieldAttributes("Title", "ShortText")>
@listItem.Fields.Title
</div>
<div class="sfMultiRelatedItmsWrp">
<h2 class="sfrelatedItmTitle">Related pages</h2>
@{
var node = PageManager.GetManager().GetPageNode(listItem.Fields.LinkedPageUrl.Fields.Id);
var url = PageExtesnsions.GetFullUrl(node);
}
<div>@listItem.Fields.Title - @url</div>
</div>
</li>
}
</ul>
}
一个很好的起点是这篇文章