Define Properties on Content Types
Why property configuration matters
Section titled “Why property configuration matters”Properties define what authors can enter for each content type. Well-configured properties make the authoring experience intuitive — with clear labels, sensible defaults, helpful descriptions, and validation that catches errors before publishing. Poorly configured properties lead to inconsistent content, author frustration, and bugs in rendering.
Property types reference
Section titled “Property types reference”| C# Type | CMS property | Editor control | Use for |
|---|---|---|---|
string | Short string | Text input | Titles, names, short labels |
XhtmlString | Rich text | TinyMCE editor | Body content with formatting |
ContentReference | Content link | Content picker | Linking to another page or media |
ContentArea | Content area | Drag-and-drop zone | Composable block regions |
Url | URL | URL picker | External links, downloads |
bool | Boolean | Checkbox | Feature toggles, visibility flags |
int / double | Number | Number input | Counts, measurements, prices |
DateTime | Date/time | Date picker | Event dates, deadlines |
IList<string> | String list | Tag editor | Tags, categories |
Configure display attributes
Section titled “Configure display attributes”The [Display] attribute controls how a property appears in the editor.
[Display(
Name = "Page Title", // Label shown in editor
Description = "The main heading displayed at the top of the page",
GroupName = SystemTabNames.Content, // Which tab
Order = 10, // Position within the tab
Prompt = "Enter a descriptive title")] // Placeholder text
[Required]
[StringLength(100, MinimumLength = 5)]
public virtual string PageTitle { get; set; } Add validation
Section titled “Add validation”// Required field — publish blocked without value
[Required]
public virtual string Title { get; set; }
// String length limits
[StringLength(160, ErrorMessage = "Meta description must be under 160 characters")]
public virtual string MetaDescription { get; set; }
// Range validation for numbers
[Range(1, 100, ErrorMessage = "Must be between 1 and 100")]
public virtual int DisplayOrder { get; set; }
// Regular expression validation
[RegularExpression(@"^#[0-9A-Fa-f]{6}$", ErrorMessage = "Must be a hex color code")]
public virtual string AccentColor { get; set; } Organize with tab groups
Section titled “Organize with tab groups”Group related properties into tabs so the editing form stays manageable.
// Define custom tab names
public static class SiteTabNames
{
public const string SEO = "SEO";
public const string Settings = "Settings";
public const string Social = "Social Media";
}
// Use in properties
[Display(Name = "Meta Title", GroupName = SiteTabNames.SEO, Order = 10)]
public virtual string MetaTitle { get; set; }
[Display(Name = "Open Graph Image", GroupName = SiteTabNames.Social, Order = 10)]
public virtual ContentReference OgImage { get; set; }
[Display(Name = "Hide from Navigation", GroupName = SiteTabNames.Settings, Order = 10)]
public virtual bool HideFromNav { get; set; } Set default values
Section titled “Set default values”public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
HideFromNav = false;
DisplayOrder = 100;
PublishDate = DateTime.Now;
} Selection properties
Section titled “Selection properties”For properties with predefined choices, use selection factories.
// Define the options
public class ColorSelectionFactory : ISelectionFactory
{
public IEnumerable<ISelectItem> GetSelections(
ExtendedMetadata metadata)
{
return new ISelectItem[]
{
new SelectItem { Text = "Primary Green", Value = "primary" },
new SelectItem { Text = "Dark", Value = "dark" },
new SelectItem { Text = "Light", Value = "light" },
};
}
}
// Use on property
[SelectOne(SelectionFactoryType = typeof(ColorSelectionFactory))]
[Display(Name = "Color Theme", Order = 60)]
public virtual string ColorTheme { get; set; } 1. Your content type has 25 properties covering page content, SEO metadata, social sharing, and display settings. Editors complain the form is hard to navigate. What is the recommended approach to improve the editing experience?
Tab groups organize related properties into separate tabs within the editing form, keeping each tab focused and manageable. This is the standard approach for content types with many properties.
Tab groups organize related properties into separate tabs within the editing form, keeping each tab focused and manageable. This is the standard approach for content types with many properties.
Review this topic →2. You need a property where editors select from a predefined list of color themes (Primary Green, Dark, Light). The list should be maintainable without redeploying. Which approach is most appropriate?
A selection factory (ISelectionFactory) with [SelectOne] provides a dropdown in the editor with predefined choices. The factory class can be updated to add or modify options as needed.
A selection factory (ISelectionFactory) with [SelectOne] provides a dropdown in the editor with predefined choices. The factory class can be updated to add or modify options as needed.
Review this topic →3. You want articles to require a meta description that is no longer than 160 characters, with a clear error message if the editor exceeds the limit. Which validation approach achieves this?
The [StringLength] attribute with a maximum length and a custom ErrorMessage provides built-in validation directly in the editor, blocking publish with a clear message when the limit is exceeded.
The [StringLength] attribute with a maximum length and a custom ErrorMessage provides built-in validation directly in the editor, blocking publish with a clear message when the limit is exceeded.
Review this topic →