Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EPiServer: Example of using IValidate
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.SpecializedProperties;
using EPiServer.Validation;
namespace EPiServerSite5.Models.Pages
{
public class StartPageValidator : IValidate<StartPage>
{
public IEnumerable<ValidationError> Validate(StartPage instance)
{
if (!instance.Name.StartsWith("X"))
{
return new[]
{
new ValidationError
{
ErrorMessage = "Should not start with X",
PropertyName = "PageName",
Severity = ValidationErrorSeverity.Warning
}
};
}
return new ValidationError[] { };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment