Created
April 1, 2015 08:52
-
-
Save fredrikhaglund/44d494d04e2ffd4e8cbd to your computer and use it in GitHub Desktop.
EPiServer: Example of using IValidate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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