Skip to main content

Posts

Validating for uniqueness with EPiServer

This is just a short post describing a method found for validating that the value provided for field within a page or block is unique across other instances of that content type. The specific need was for a poll block that provided a question and set of answers for users to pick from, with the results being saved to the dynamic data store. I had an "identifier" field that the editors had to complete, the value of which being unique across all polls. And rather than relying on them to remember that, it's obviously better to validate it. Here was the solution. Firstly I created an extension method that gets a list of all blocks of a given type other than the current block, looking like this: public static IEnumerable<T> GetOtherContentData<T>(this T instance) where T : IContentData { var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var contentModelUsage = ServiceLocator.Current.GetIn...