Loading...

Last updated: Jun 28 2018

Area: Episerver CMS Applies to versions: 11.1 and higher

Property Value List

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 Episerver 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; }

Validation

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:

[ListItems(5)]
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; }

[ItemRegularExpression("[a-zA-Z]*")]
public virtual IList<string> LettersOnly { get; set; }

[ItemStringLength(3)]
public virtual IList<string> ListOfAcronyms { get; set; } 

Rendering

To render a list:

[Required]
[Display(Order = 305)]
[CultureSpecific]
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:

[UIHint("StringsCollection")]
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())
{
    <ul>
        @foreach(var stringValue in Model)
        {
            <li>@stringValue</li>
        }
    </ul>
}

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 have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/