Try our conversational search powered by Generative AI!

IValidate interface for multiple pagetypes


Hi All,

I am new to EPiServer. I am using IValidate interface for validating the default property of episerver page i.e CategoryList. I would like to restrict the count of category selection for example say only one category should be selected. I did this for a single pagetype, But i am getting the following exception , while adding additional page types,"Ambiguous match found". It may be simple one i may not know. I have attached my code below.

public class BasePageValidator : IValidate,IValidate

        IEnumerable IValidate.Validate(SamplePage page)
            if (page != null && page.Category.Count > 1)
                return new[] 
                    new ValidationError() 
                       ErrorMessage = "Field IntroText cannot be empty!", 
                       PropertyName = page.GetPropertyName(pg => pg.Category),
                       Severity = ValidationErrorSeverity.Warning, 
                       ValidationType = ValidationErrorType.AttributeMatched
            return Enumerable.Empty();;

        IEnumerable IValidate.Validate(Products page)
           return Enumerable.Empty();

It is not working after adding "IValidate", getting an exception.

I need to set this restriction for some pagetypes more than one. Suggest me on how to achive this one.

Thanks in advance.

Jan 18, 2016 14:27


If I remember correctly IValidate supports being registered against interfaces. So you could add an interface to SamplePage and Products, something like IMustHaveCategory, and then register your validator as IValidate<IMustHaveCategory>. Would that work?


Per Gunsarfs

Jan 18, 2016 14:57

Is it possible to highlight a field with yellow colour if it fails validation with severity warning. Currently, only for severity Error it highlights the field with red colour, ex: Required field validation.

Nov 21, 2019 17:43
- Feb 21, 2020 14:17
It would be possible to add this functionality using Dojo. But there is no built in support for this.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.