2

I am working on a view rendering and trying to get a list of selected items from a multilist field.

I don't know if it matters, but the list field I am trying to get the selected items from is a child of the Model.Item.

The Children items have a field called "Selected Items" which is a MultiList field type. I can't figure out how to get anything out of the "selectedItems" object.

How to get the value of a text field on each selected item?

    @foreach (Item item in Model.Item.Children)
    {
            MultilistField selectedItems = item.Fields["Selected Items"];
    }
3

Your selectedItems will have GetItems(). That will give you a list of all referred items in the field. Just loop over them with another foreach and get the text field you need from each of those items. That should do the trick.

@foreach (Item referred in selectedItems.GetItems())
{
    ... = referred.Fields[".."]; 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.