gpt4 book ai didi

c# - 限制 block 只能在从 EpiServer 中的某个接口(interface)继承的 ContentArea 中使用

转载 作者:太空宇宙 更新时间:2023-11-03 23:06:53 24 4
gpt4 key购买 nike

这个问题我想了很久。想象一下,我有一个 block 应该从它被放在 ContentArea 中的页面访问属性。我有多个页面,其中每个页面都应该与这个 block 兼容,必须从接口(interface)继承(我们称之为 IHaveProperties)并实现这些属性,以便我可以将“currentPage”转换为这个接口(interface)和从而访问其中的属性。

我唯一的问题是用户在编辑模式下倾向于将此 block 放到该 block 不属于的内容区域。这是我主要关心的问题。如果页面上的 ContentArea 是 IHaveProperties 接口(interface)的实现,那么我是否可以限制该 block ,以便它只能被放到作为该接口(interface)实现的 ContentArea 上?

或者另一种方法是在该 BlockType 的界面中有一个内容引用,并在没有内容区域的情况下呈现它?

我希望有 ContentArea 解决方案...

最佳答案

是的,您可以通过向 ContentArea 属性添加一个属性来做到这一点,如下所示:

[AllowedTypes(typeof(IHaveProperties))]
public virtual ContentArea SomeContentArea { get; set; }

这里有一篇来自 EPiServer 的精彩帖子:

http://world.episerver.com/blogs/Ben-McKernan/Dates/2015/2/the-new-and-improved-allowed-types/

关于c# - 限制 block 只能在从 EpiServer 中的某个接口(interface)继承的 ContentArea 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40917621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com