SelectMany attribute not working for IList<PageReference> type of property in page type

Vote:
 

Hi,

We have a scenario where we need to store multiple page references/content references in a property of a page type.

Here is sample code for the property-

[SelectMany(SelectionFactoryType = typeof(ContactPageSelectionFactory))]

public virtual IList MyContactLink { get; set; }

I have also created a class for property-

[PropertyDefinitionTypePlugIn]
public class PropertyPagesReference : PropertyListBase
{
}

SelectionFactory class -

public class ContactPageSelectionFactory : ISelectionFactory
{
private Injected ContentLocator { get; set; }

public IEnumerable GetSelections(ExtendedMetadata metadata)
{
var contactPages = ContentLocator.Service.GetContactPages();

return new List(contactPages.Select(c => new SelectItem {Value = c.PageLink, Text = c.Name}));
}
}

Above sample code is referring Alloy MVC template.

As SelectMany has Checkbox list in the backend property window which is coming up there but could not save the values.

Thanks,

Avi

Can someone help me in getting this resolved.

#182302
Sep 14, 2017 17:58
Vote:
 

I'm not sure there's an editor out of the box for PageReferences, personally I've always just done with a ContentArea restricted down to PageReference types then they can just drag the pages in from the site navigiation tree. However Patrick Van Kleef has another solution here https://www.patrickvankleef.com/2015/02/22/multiple-page-picker-property-in-dojo/

#182325
Sep 15, 2017 10:43
Vote:
 

Thanks for the response.

Our reuirement is to display pages names in a check-box list so that user can select the pages.

#182327
Edited, Sep 15, 2017 11:05
Vote:
 

Okay sorry I didn't read it properly. I've use ILists and SelectMany quite a few times before but usually the IList was connected to an editor descriptor, I'm wondering how the selection factory is being implictly converted to IList<PageReference>. Does it work if you change the type instead to string? Do you get a delimited list of references? If so you could create a propertly to split these and load them in to the PageReference collection.

#182328
Sep 15, 2017 11:26
Vote:
 

I am getting a string of all the page reference ids deliminated by ,. So it gives error when it tries to save the selected values.

Since I am new to Episerver development, it would be great help if you could provide the required changes as suggested in earlier post.

Thanks,

Avi

#182387
Sep 18, 2017 6:00
Vote:
 

I don't think the IList code has been built to allow saving of page references only string data. I'd suggest the simplest solution is just saving as delimited strings by changing to string and then creating another virtual property returning an IEnumerable<PageReference> by splitting them and loading them via the ContentLoader service.

#182394
Sep 18, 2017 9:58
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.