Try our conversational search powered by Generative AI!

Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Property attributes

This topic describes attributes available for properties in Episerver.

How it works

For properties of content types we use different attributes to describe how they should behave.

The following are located in the EPiServer.DataAnnotations namespace.

Attribute nameDescriptionBehavior if not specified
BackingType(Type) Defines the PropertyData type used to store values for this property. Must be a type inheriting from PropertyData. The backing type will be auto determined. See Default Backing Types.
CultureSpecific(bool) Defines if this property should have a different value for each language. Properties will not be culture-specific.
Searchable(bool) Defines if the property value should be searchable. String properties will be searchable, all other property types will not.
Ignore Should never be used on cached objects. Since the content holding this property is stored in the cache, it is not possible to store request scoped data on it, as that will lead to serious concurrency issues.
AllowedTypes Allows/Restricts certain items to be added to the property. This attribute only works with ContentArea, ContentReference and ContentRefeferenceList type properties. See Restricting content types. By default all items are allowed to be added to the property. 

The following are located in the System.ComponentModel.DataAnnotations namespace.

Attribute NameDescriptionBehavior if not specified
Required Defines if a value for this property must be set before being able to save a page of the parent type. Property value is not required.
ScaffoldColumn(bool) Defines if this property is visible in edit view. Property is visible in edit view.
Order=..., Prompt=...)
The Name, Description, GroupName, Order and Prompt properties are used to set the EditCaption, HelpText, Tab, FieldOrder and placeholder/watermark text respectively. EditCaption is set to the name of the property. HelpText is NULL. Prompt is NULL.
UIHint Used to select either editor/renderer or both by defining a hint string. You can use EPiServer.Web.UIHint to use hints for known types in the system, for instance UIHint.Image. The default editor and renderer for the type will be used.
StringLength Sets a maximum length for strings. Note that this attribute cannot be used for properties of type XhtmlString. No length restriction.
RegularExpression Validates the input format. Usually used for string properties. No validation of the input.
Range Determines the valid range for numeric properties. No validation of range except the minimum/maximum values for the value type (For instance Int32.MinValue and Int32.MaxValue).
Editable Indicates whether a property is editable. Properties is editable.

The following images show how the attributes are mapped to settings in admin view:


Default backing types

If the BackingType attribute has not been set for a property, the backing type will be automatically assigned to a PropertyDefinitionType where the corresponding EPiServer.Core.PropertyData.PropertyValueType matches the property type. That means that if there is a PropertyData implementation (can be a custom property) with matching PropertyValueType that definition will be used. Otherwise the backing type is assigned according to this table.

See built-in property types for details on using the correct type.

Property typeBackingType
ContentArea PropertyContentArea
Boolean PropertyBoolean
CategoryList PropertyCategory
DateTime PropertyDate
Double PropertyFloatNumber
LinkItemCollection PropertyLinkCollection
Int32 PropertyNumber
PageType PropertyPageType
String PropertyLongString
TimeSpan PropertyTimeSpan
Url PropertyUrl
XForm PropertyXForm
XhtmlString PropertyXhtmlString
Blob PropertyBlob
IList<ContentReference> PropertyContentReferenceList

Sample code

Sample code using many of the attributes described in this article.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EPiServer.Core;
using EPiServer.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using EPiServer.Security;
using EPiServer;
using EPiServer.Web;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;
using EPiServer.Shell.ObjectEditing;
using EPiServer.DataAbstraction;

namespace CodeSamples
        DisplayName="My Page Type",
        Description="Description for this page type",
        GroupName="My Group",
    [AvailableContentTypes(Include = new Type[] { typeof(MyPageType2), typeof(MyPageType3) })]
    [Access(Users = "niis", Roles = "CmsEditors")]
    public class TypedPageWithAttributeSample : PageData
            Name = "My Heading",
            Description = "Heading for my page type.",
            GroupName = "My Tab",
            Order = 64)]
        public virtual string Heading { get; set; }

        //An integer between 0 and 130.
        [Range(0, 130)]
        public virtual int Age { get; set; }

        //Validating against a given regular expression.
        public virtual string CustomValidation { get; set; }

        //A string with a maximum length of 20 characters.
        public virtual string Header { get; set; }

        //Any URL
        public virtual Url RedirectPage { get; set; }

        //Reference to an image in the EPiServer media system.
        public virtual ContentReference Logotype { get; set; }

        //URL to image is also supported but mostly for upgrade support or when there is a need to add custom query parameters to the URL.
        public virtual Url LogotypeAsUrl { get; set; }

        //Creates a selection of predefined values.
        public virtual string LanguageSelection { get; set; }

         //Creates a selection of predefined values with the option to select several items.
        public virtual string MultipleLanguageSelection { get; set; }

    public class CustomLanguageSelectionFactory : ISelectionFactory
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
            var languages = new List<SelectItem>();

            languages.Add(new SelectItem() { Text = "English", Value = "en"});
            languages.Add(new SelectItem() { Text = "Swedish", Value = "sv" });
            languages.Add(new SelectItem() { Text = "Norwegian", Value = "no" });

            return languages;

    [AvailableContentTypes(IncludeOn = new Type[] { typeof(TypedPageWithAttributeSample) })]
    public class MyPageType1 : PageData { }

    [AvailableContentTypes(Exclude = new Type[] { typeof(TypedPageWithAttributeSample) })]
    public class MyPageType2 : PageData { }

    [AvailableContentTypes(ExcludeOn = new Type[] { typeof(MyPageType1) })]
    public class MyPageType3 : PageData { }

    [AvailableContentTypes(Availability = Availability.None)]
    public class MyPageType4 : PageData { }



Do you find this information helpful? Please log in to provide feedback.

Last updated: Sep 21, 2015

Recommended reading