-
Notifications
You must be signed in to change notification settings - Fork 58
Model
All property editors can return a Picker object as their model. This can be done using the built-in Umbraco PropertyValueConverter, or via the public constructor (supplying a content, media or member id together with a property alias):
@using nuPickers;
var picker = new Picker(1000, "examplePicker");
There is also an extension method available on IPublishedContent:
@using nuPickers;
@using nuPickers.Extensions;
var content new UmbracoHelper(UmbracoContext.Current).TypedContent(1000);
var picker = content.GetPicker("examplePicker);
The Picker object has a property "PickedKeys" which is a IEnumerable<string>
this collection will always contain the raw keys (id's etc) of the picked items.
@{
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 pickedEnums = Model.Content.GetPropertyValue<Picker>("enumCheckboxPicker");
<ul>
@foreach (var myEnum in pickedEnums.AsEnums<MyEnumType>())
{
<li>@myEnum</li>
}
</ul>
}
@{
var pickedEnums = CurrentPage.enumCheckboxPicker;
<ul>
@foreach (var myEnum in pickedEnums.AsEnums())
{
<li>@myEnum</li>
}
</ul>
}