Try our conversational search powered by Generative AI!

Custom validation on EPi 7


Hi, guys,

Have you tried out EPi 7's custom validation?

The error is returned when the validation condition is broken. However, when I fix the thing that is causing the validation error, auto save always returns: "Offline, can't save" and hitting Publish, gives me the validation error.

This is the code:

    public class RowBlockValidator : IValidate<RowBlock>
        IEnumerable<ValidationError> IValidate<RowBlock>.Validate(RowBlock instance)
            if (instance.OneToFourBlocks != null)
                if (instance.OneToFourBlocks.Count > 4)
                    var validationError = new ValidationError
                        ErrorMessage = "Content area can contain up to four blocks",
                        PropertyName = "OneToFourBlocks",
                        RelatedProperties = new string[] { "OneToFourBlocks" },
                        Severity = ValidationErrorSeverity.Error,
                        ValidationType = ValidationErrorType.AttributeMatched

                    return new[] {validationError};

            return null;


Jan 18, 2013 15:04


I've built a number of custom IValidate classes and have never experienced such issues. I have however never set anything else than ErrorMessage and PropertyName on my ValidationErrors. I usually also return Enumerable.Empty<ValidationError>(). Neither of those differences should matter though.

Jan 18, 2013 23:36

Hi Marija

I had same problem as you had, I can't recreate it, but it did happen few times to me. 

Jan 20, 2013 23:51

Now, I have changed it to return Enumerable.Empty<ValidationError>(); and tried out a couple of times with this and return null.

Every time return null gives me the problem described and return Enumerable.Empty<ValidationError>(); gives me the correct behavior.

Jan 21, 2013 11:06
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.