HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Properties are the fields in content such as pages and blocks, where editors enter information. You can apply different attributes to properties, to describe their purpose and how they should behave.

Consider the following when working with properties:

  • Use an intuitive naming of properties in code, and set a "friendly" display name and description, to help editors understand the purpose of a property (attributes `Name`, `Description`).

  • Organize related properties under the same tab in edit view, and in a logical order with the most frequently used ones at the top (attributes `GroupName` and `Order`).

  • Consider adding field value validation, default values, or required fields, where applicable.

## Available attributes

The following attributes 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`Property is ignored by Optimizely CMS and will not be backed by a `PropertyData` type. <br> <br>(When the property is ignored by CMS, it is technically possible to assign the property even though the content is read-only. To avoid that, implement a setter that checks the `IsReadOnly` property before assigning any fields. Content is stored as read-only singletons in the cache so it is not possible to use ignored properties for assigning state related to a single request, as that would cause serious concurrency issues.)Property is not ignored.
`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 attributes 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.
`Display(` <br>`Name=..., ` <br>`Description=..., ` <br>`GroupName=..., `<br>`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 add 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 image 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

## Examples

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