BlockType / PageType上的条件验证

时间:2018-04-11 13:15:41

标签: episerver

我有一个具有这两个属性的Block Type。

[CultureSpecific]
[Display(
Name = "Display PDF Button", GroupName = TabNames.PDFCustomisation, Order = 0)]
public virtual bool DisplayPdfButton { get; set; }

[CultureSpecific]
[Required]
[Display(
Name = "Download Pdf Text", GroupName = TabNames.PDFCustomisation, Order = 1)]
public virtual string DownloadPdfText { get; set; }

如果用户将DisplayPdfButton设置为True,我只需要DownloadPdfText。 - 这可以在Episerver中做到吗?

2 个答案:

答案 0 :(得分:2)

另一种方法是为自定义验证实现事件处理程序,例如SavingContentPublishingContent事件。

这样,您可以查看正在保存和/或发布的内容类型,并决定是否验证。

事件处理程序参数具有可以设置为停止保存/发布的属性,还可以指定原因(查看CancelActionCancelReason属性)。

Here is an example of such an event handler.

答案 1 :(得分:1)

这样做的一种方法是实现自己的验证属性。如果选中DisplayPdfButton并且DownloadPdfText为空,则可以将其验证为false。请在此处阅读有关如何执行此操作的信息:https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Content/Properties/Property-types/Writing-custom-attributes/