Try our conversational search powered by Generative AI!

Using a SelectionFactory with ConentReference property issue

Vote:
 

I am attempting to use a selection factory to make choosing a specific kind of content type simpler. I am using a variation of this type of selection factory to list my content in a dropdown:
https://github.com/alfnilsson/episerverutils/blob/master/SelectContent/ContentSelectionFactory.cs

The problem is the property I am using the factory on will not serialize the selected value into a ContentReference properly. I get an error "Unable to cast object of type 'System.String' to type 'EPiServer.Core.ContentReference'" when saving the item. It works fine if I change the property to a string though, but it forces me to parse it into a ContentReference manually if I want to use it in code. 

#206596
Aug 26, 2019 11:12
Vote:
 

Hi George,

Have you tried declaring your property like this way:

[SelectOne(SelectionFactoryType = typeof(ContentSelectionFactory<IContentData>))]
public virtual ContentReference Content { get; set; }

It works fine for me to save item as ContentReference :)

#206624
Edited, Aug 27, 2019 10:40
* 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.