-
Notifications
You must be signed in to change notification settings - Fork 58
Property Value Converter
All nuPicker property editors return a "Picker" object. Picker has a property "PickedKeys" which is a IEnumerable<string>
this collection will always contain the raw keys (id's etc) of the picked items.
For all of the typed models you will need to have a reference to nuPickers.PropertyValueConverters.
e.g. @using nuPickers.PropertyValueConverters
@{
var pickedItems = Model.Content.GetPropertyValue<Picker>("myNuPickerPropertyAlias");
<ul>
@foreach (var item in pickedItems.PickedKeys)
{
<li>@item</li>
}
</ul>
}
@{
var dynamicPickedItems = CurrentPage.myNuPickerPropertyAlias;
<ul>
@foreach (var item in dynamicPickedItems.PickedKeys)
{
<li>@item</li>
}
</ul>
}
There are a number of helper methods within the "Picker" to make rendering easy.
If your picked keys are either Umbraco Content, Media or Members then these methods will return them as IPublishedContent or DynamicPublishedContent, the method you need to use depends on if you are using strongly typed (Model.Content
) or dynamic (CurrentPage
) Umbraco models.
@{
var pickedItems = Model.Content.GetPropertyValue<Picker>("myNuPickerPropertyAlias");
<ul>
@foreach (var item in pickedItems.AsPublishedContent())
{
<li>@item.Name - @item.GetPropertyValue("title")</li>
}
</ul>
}
@{
var dynamicPickedItems = CurrentPage.myNuPickerPropertyAlias;
<ul>
@foreach (var item in dynamicPickedItems.AsDynamicPublishedContent())
{
<li>@item.Name - @item.title</li>
}
</ul>
}
If you are using the Enum Pickers then you can use these methods to easily be returned the Enum that was selected
@{
var pickedEnum = Model.Content.GetPropertyValue<Picker>("enumCheckboxPicker");
<ul>
@foreach (var myEnum in pickedEnum.AsEnum<MyEnumType>())
{
<li>@myEnum</li>
}
</ul>
}
@{
var pickedEnum = CurrentPage.enumCheckboxPicker;
<ul>
@foreach (var myEnum in pickedEnum.AsEnum())
{
<li>@myEnum</li>
}
</ul>
}