BlockType/PageType 的条件验证
Conditional Validation on a BlockType/PageType
我有一个具有这两个属性的块类型。
[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 中实现吗?
实现此目的的一种方法是实现您自己的验证属性。如果选中 DisplayPdfButton 并且 DownloadPdfText 为空,您可以将其验证为 false。在此处阅读有关操作方法的信息:https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Content/Properties/Property-types/Writing-custom-attributes/
另一种方法是实现自定义验证的事件处理程序,例如 SavingContent
或 PublishingContent
事件。
这样,您可以查看正在保存的内容类型 and/or 发布,并决定是否验证。
事件处理程序参数具有可以设置为停止 saving/publishing 的属性,还可以指定原因(查看 CancelAction
和 CancelReason
属性)。
我有一个具有这两个属性的块类型。
[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 中实现吗?
实现此目的的一种方法是实现您自己的验证属性。如果选中 DisplayPdfButton 并且 DownloadPdfText 为空,您可以将其验证为 false。在此处阅读有关操作方法的信息:https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Content/Properties/Property-types/Writing-custom-attributes/
另一种方法是实现自定义验证的事件处理程序,例如 SavingContent
或 PublishingContent
事件。
这样,您可以查看正在保存的内容类型 and/or 发布,并决定是否验证。
事件处理程序参数具有可以设置为停止 saving/publishing 的属性,还可以指定原因(查看 CancelAction
和 CancelReason
属性)。