Area: Optimizely CMS
Applies to versions: 11.1 and higher

Property Value List

Recommended reading 

Property Value List allows the editors to input multiple primitive values.

The available and supported types are:

  • String
  • Int
  • DateTime
  • Double

The idea is the same as with the List<T>, you add the list as a new property to your model, and the default descriptors match IList  type and render the correct editor.

public virtual IList<string> ListOfStrings { get; set; }

public virtual IList<int> ListOfIntegers { get; set; }

public virtual IList<DateTime> ListOfDates { get; set; }

public virtual IList<double> ListOfDoubles { get; set; }

Note: The property type does not have to be IList. The Optimizely descriptors are configured to match the IList interface but they also cover all base ones, so if you prefer to use IEnumerable or ICollection you can do so. All the following declarations are matched by the Value List descriptor.

public virtual IEnumerable<string> EnumerableStrings { get; set; }
public virtual ICollection<string> CollectionOfStrings { get; set; }
public virtual IList<string> ListOfStrings { get; set; }


You can apply validation to both the list itself and to the individual items, and you can use ListItemsAttribute in order to control the number of items in the list:

public virtual IList<int> Max5Items { get; set; }

The attributes that can be applied to individual items are:

[ItemRangeAttribute(1, 10)]
public virtual IList<int> ItemsBetween1And10 { get; set; }

public virtual IList<string> LettersOnly { get; set; }

public virtual IList<string> ListOfAcronyms { get; set; } 


To render a list:

[Display(Order = 305)]
public virtual IList<string> UniqueSellingPoints { get; set; }

To use the PropertyFor helper method you must define a specific Display template, and to do that you must first attach a UIHint to your property:

public virtual IList<string> UniqueSellingPoints { get; set; }

Then add a StringsCollection.cshtml file to the ~/Views/Shared/DisplayTemplates folder.

An example of a Display Template can be seen in the Alloy package:

@model IEnumerable<string>
@if(Model != null && Model.Any())
        @foreach(var stringValue in Model)

Add a UniqueSellingPoints property to your page template:

@Html.PropertyFor(x => x.CurrentPage.UniqueSellingPoints)

And you will see the following result in on-page edit:

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

Last updated: Jun 28, 2018

Recommended reading