Skip to content

Instantly share code, notes, and snippets.

@fredrikhaglund
Created April 1, 2015 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrikhaglund/44d494d04e2ffd4e8cbd to your computer and use it in GitHub Desktop.
Save fredrikhaglund/44d494d04e2ffd4e8cbd to your computer and use it in GitHub Desktop.
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