ContentSerice saving data
# help-with-umbraco
t
Hi I have a blocklist (element type Umbraco 13). I use contentService to save data and simple types like text is saved successfully through C# code. For the element type field, I type in the name of the property but it says the property name does not exist. I managed to find test JSON data for an existing row I saved and change some data to insert from C# but it never saves. I always get some error or another. How to save element data with contentService? Thank you in advance
l
As far as I know you just need to know the correct syntax for complex types. The IContentService is a service that works almost directly on the database, so setting complex properties in code is a pain.
For the cached version of the data, the data from a property editor is converted using a PropertyValueConverter. These don't work in IContent, but perhaps you can look at the source code of the PropertyValueConverter of your property to see how the data is serialized/deserialized.
t
I could try that. Where do I look for that sample data for my property? I only have one property on the element
I copied the JSON on the Umbraco site then changed the JSON for the property I have in mine version
m
I did this recently and it was a little fiddly but you need to pull different examples together for it to work. One of the gotyas for me when selecting the parent node the SetValue in ContentService for the blocklist must reference the GUID of the blocklist otherwise it failed to insert data. Feel free to get back if you still need some help.
2 Views