Single or multiple list options
Describes how to define SelectOne or SelectMany attributes on a property and require a reference to a class implementing the ISelectionFactory interface.
Set up single or multiple selections from a list of predefined values using the SelectOne and SelectMany attributes. These attributes are in the EPiServer.Shell.ObjectEditing namespace in the EPiServer.UI assembly. Define them on a property and reference a class implementing the ISelectionFactory interface:
[ContentType]
public class SamplePage: PageData {
[SelectOne(SelectionFactoryType = typeof (LanguageSelectionFactory))]
public virtual string SingleLanguage {
get;
set;
}
[SelectMany(SelectionFactoryType = typeof (LanguageSelectionFactory))]
public virtual string MultipleLanguage {
get;
set;
}
}
public class LanguageSelectionFactory: ISelectionFactory {
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata) {
return new ISelectItem[] {
new SelectItem() {
Text = "English", Value = "EN"
}, new SelectItem() {
Text = "Swahili", Value = "SW"
}, new SelectItem() {
Text = "French Polonesia", Value = "PF"
}
};
}
}Create your attributes
Custom attributes let you follow the DRY principle and avoid repeating selection factory references across properties. If you use the same factory in several places, create a custom attribute. Inherit from the EPiServer attributes and override the SelectionFactoryType property:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class LanguageSelectionAttribute: SelectOneAttribute {
public override Type SelectionFactoryType {
get {
return typeof (LanguageSelectionFactory);
}
set {
base.SelectionFactoryType = value;
}
}
}Updated 18 days ago
