API Reference: ReadOnlyAttribute Class

The ReadOnlyAttribute can be applied to content model properties. The attribute specifies that this property will always be rendered in read-only mode, and editing is not possible in the back office. The property will still be displayed, as opposed to the IgnoreMember attribute, which hides the property from the back office completely.

The property value may still be modified by scripting or within the content model class itself.

Usage

Decorate the model class with the ReadOnlyAttribute. No additional parameters are required. The attribute is not required for properties that do not have a setter, as they are always treated as read-only.

Example

[Asset]
public class ContactPerson: IContentType
{
        public string FirstName { get; set; }

        public string LastName { get; set; }

        [ReadOnly]  // This property cannot be edited in the back office.
        public string EmailAddress { get; set; }

        // This property has no setter and is therefore read-only by default.
        public string FullName => this.FirstName + " " + this.LastName;
}