为什么我的 Orchard 驱动程序返回多个内容形状?

Why is my Orchard driver returning multiple content shapes?

我只想为 "Parts_McrfProfile_List" 构建形状,但无论出于何种原因,"Parts_McrfProfile_Summary" 总是被击中。任何人都可以引导我朝着正确的方向前进,为什么会一直发生这种情况?

这是我的驱动程序的代码:

    protected override DriverResult Display(
        McrfProfilePart part, string displayType, dynamic shapeHelper)
    {
        return Combined(
       ContentShape("Parts_McrfProfile",
                         () =>
                         {
                             part.ProfileDetail = _profileService.GetProfileDetail(part.ProfileId);

                             McrfProfileDetailViewModel profileDetailViewModel = new McrfProfileDetailViewModel();

                             profileDetailViewModel.ProfileDetail = part.ProfileDetail;

                             return shapeHelper.Parts_McrfProfile(ProfileDetail: profileDetailViewModel);
                         }),
        ContentShape("Parts_McrfProfile_List",
                         () =>
                         {
                             return shapeHelper.Parts_McrfProfile_List(ProfileRecord: part);
                         }),
        ContentShape("Parts_McrfProfile_Summary",
                         () =>
                         {
                             McrfProfileSummaryViewModel profileSummaryViewModel = new McrfProfileSummaryViewModel();

                             List<int> profileID = new List<int>() { part.ProfileId };

                             var summary = _profileService.GetProfileSummaryList(profileID).Where(e => e.ProfileID == part.ProfileId).First();

                             profileSummaryViewModel.JobTitle = summary.JobTitle;
                             profileSummaryViewModel.Name = summary.Name;
                             profileSummaryViewModel.ProfileImage = summary.ProfileImage;
                             profileSummaryViewModel.ProfileID = summary.ProfileID;

                             return shapeHelper.Parts_McrfProfile_Summary(ProfileRecord: profileSummaryViewModel);
                         }));

    }

调用代码如下:

foreach (var contentItem in contentItems.ContentItems)
{
                               list.Add(_mcrfContentManager.BuildDisplay(contentItem.Content, "Parts_McrfProfile_List"));
}

您需要使用模块中的 placement.info 文件来控制显示驱动程序中的哪些形状。在您的 BuildDisplay 方法中,第二个参数是显示类型,而不是您想要的形状 return。你真的想要这样的东西:

.BuildDisplay(contentItem.Content, "ListView")

然后在您的展示位置文件中:

<Match DisplayType="Detail">
    <Place Parts_McrfProfile="Content:1" />
</Match>
<Match DisplayType="ListView">
    <Place Parts_McrfProfile_List="Content:1" />
</Match>
<Match DisplayType="Summary">
    <Place Parts_McrfProfile_Summary="Content:1" />
</Match>