Try our conversational search powered by Generative AI!

PropertyList with string collection losing data when editing entry



We need to store information about location into the property which is something like country + X cities. I thought it would be great to use for that PropertyList, so defined class for location like:

    public class Location
        public string Country { get; set; }

        public IList Cities { get; set; }

after that added to my page type property:

        [Display(Order = 40)]
        [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor))]
        public virtual IList Locations { get; set; }

and also added class:

    public class LocationListProperty : PropertyList


As an effect I got nice looking property for locations

but the issue is when you click edit on single row the values from Cities list are lost

Do I have something missing still to make it working? or is the PropertyList not designed to use collections in the class?

I assumed that do not need anymore to do serializer tricks which were needed in earlier Episerver (when it was Beta version) explained here

Mar 15, 2018 10:32

you might need to put a json converter on type of your list property for cities.  I ran into this with the url property where when you save, the values would jsut disappear.  Try putting a JsonConverter(typeof(xxx)) on type of your Cities properties.

Mar 16, 2018 15:02

Hi Joshua,

I have tried what you suggested, implemented the converter based on that implementation and then decorated my property like:

        public IList<string> Cities { get; set; }

But still no luck and same behavior.

Edited, Mar 16, 2018 23:14

Greg, I tried this with Alloy site. Changing the editor for the Cities list to the Alloy StringListEditorDescriptor gets a "working" edit but naturally it is displaying the textarea editor where you put the "city name" on a separate line.

[EditorDescriptor(EditorDescriptorType = typeof(Business.EditorDescriptors.StringListEditorDescriptor))]
public IList<string> Cities { get; set; } = new List<string>();

It isn't what you are trying to achieve, but maybe a hint that you should create own editor to make it work. Maybe the editor what you get is just a side effect of something.

I tested also with changinig the IList<string> to ICollection<string> and then the default editor only showed properties for the ICollection: Count and IsReadOnly

Mar 17, 2018 0:33

Hi Antti, if you are talking about having that property with no use of PropertyList it works nicely then you don't even need any descriptor with IList<string> properties, but here in connection with PropertyList it fails on edit data.

It might be that editor I get now is kind of side effect of something else.

Mar 17, 2018 3:51

Hi Greg, no I meant that you only use the stringlisteditor from Alloy and decorate your Cities property with as shown above code. You still have your Locations and the same code that you originally posted. You just change the editor for the Cities list. UI works ok and you can edit existing cities list. The only downside is that the editor for the cities list is now textarea where you write each city on a separate line. In your code you can still do foreach to the locations list and foreach for the cities list.

I also tested with changing the Cities items to custom object like:

public class City
    public string Name { get; set; }
[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<City>))]
public IList<City> Cities { get; set; } = new List<City>();

This also work, only downside is the editor experience when editing the items in cities. Also when looking the all properties view of the page having the locations property, the editor displays the locations property something like this:

Finland [object Object], [object Object]
Sweden [object Object]
Mar 17, 2018 9:31

Alright, I will then try to get the StringListEditorDescriptor from Alloy and decorate Cities property. The fact it is textarea is still acceptable, since I assume in most of the cases, pages will be handled anyway only by scheduled job.

As long I can iterate locations and cities from code it is fine. I wanted to avoid idea of creating separate block types for locations since it requires more complex logic to use later the data from it and PropertyList looked much more friendly in that case.

Will let you know if it worked when I find some time during weekend, thanks for now!

Mar 17, 2018 9:55

Hi Antti, it works! Please take the credit :)

As you said the only negative thing it is showing cities as textarea, each value in separate line, but I would say it is acceptable in that case.

However I would like to hear from someone from Epi core team if that is the way or we missed some other recommended approach.

Mar 18, 2018 19:06

Greg, maybe it would be good idea to create a developer ticket about this. Maybe there is currently a bug and it will get fixed or maybe a feature the development team can easily implement.

Mar 19, 2018 6:25

I have created support ticket as well, will keep you informed how it ended

Mar 19, 2018 13:20

Got an answer to my ticket:

Hi Grzegorz,

The PropertyList was designed primarily to be used with simple types such as int, string, etc and the “out-of-the-box experience” will only cater for such types. If you want to use a more complex type as described in the forum thread, both responsible for making sure that the type can be serialized (using Json.NET) and that it’s properly decorated for editing. I hope this will clarify your concern.

Support Team
Mar 21, 2018 7:37

We have already fixed that issue. It will be released in 11.4.2 or 11.5.0.

Edited, Mar 22, 2018 9:14

Thanks a lot Bartek!

Looking forward for the release, any kind of estimate when it will come?

Mar 22, 2018 9:25

And Bartosz one more thing, what will be the official recommended way how to handle such cases? do we really need still to have that SingleOrArrayConverter class with decorating property with the attributes like

    public class Location
        public string Country { get; set; }
        public IList<string> Cities { get; set; }

or this is not needed anymore with your fix?

Btw 11.5 has been already released and I have still that issue on Alloy with latest

Ah or actually you are probably saying about EPiServer.CMS.UI package version release

Edited, Mar 22, 2018 9:48

Yes, sorry I should have been more specific. I meant EPiServer.CMS.UI - I'm from the UI team hence the misunderstanding :)

About your question - you don't need any attributes.

public class Location
    public string Country { get; set; }          
    public IList<string> Cities { get; set; }

public class LocationListProperty : PropertyList<Location>

and then

[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<Location>))]
public virtual IList<Location> Locations { get; set; }

in your page model would work fine.

Edited, Mar 22, 2018 11:13

Awesome, I thought so we do not need any extra stuff since I got the same result already with the code you posted above.

Looking forward to see the fix in next release (hope so) and right after that you will get your answer marked as solution ;)

thanks (dzięki), Greg

Mar 22, 2018 12:42

Fix has been released in update 208

Thanks once again Bartosz!

Apr 03, 2018 22:29
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.