Can I write Collection of IPublishedContent back to Model Property?
Hi!
In other words - can I create Nested Content list programmatically and store it in my Model?
I've seen that internally in umbraco Property stored a json with all nested documents.
I can manually deserialize and serialize my nested documents, but maybe this solved already? I've digged into source on github, but have not found any serialisations.
I've done so, and all works good.
I prefer therefore a solution, where I can make a List of i.e. IContent and set it to NC property:
var list = new List
I know, this is not umbraco way.
I'm new in umbraco and c#, but I wonder, why we can absolutely clear and easy get deserialized value from IPublishedContent property, i.e. myCont.GetPropertyValue
The idea behind IPublishedContent is that it is read-only, (not programmatically, but conceptually). Values are taken from the properties and displayed on the front-end.
There was no intention for IPublishedContent to be used to write data back to the CMS/database. That's what IContent was designed for.
Can I write Collection of IPublishedContent back to Model Property?
Hi!
In other words - can I create Nested Content list programmatically and store it in my Model?
I've seen that internally in umbraco Property stored a json with all nested documents.
I can manually deserialize and serialize my nested documents, but maybe this solved already? I've digged into source on github, but have not found any serialisations.
Many Thanks!
Hi Leo,
The NC data is stored as a JSON blob/string in the database, in C# terms it's a serialized
Dictionary<string, object>
type.So if you want to set the NC's value, then you can built up a dictionary, serialize it and save it.
NC does have some default value, see here for details
I hope this helps?
Cheers,
- Lee
Hi Lee, Thank you!
I've done so, and all works good. I prefer therefore a solution, where I can make a List of i.e. IContent and set it to NC property:
var list = new List
I know, this is not umbraco way. I'm new in umbraco and c#, but I wonder, why we can absolutely clear and easy get deserialized value from IPublishedContent property, i.e. myCont.GetPropertyValue
Or I have missed something?
Hi Leo,
Good to hear that you have a workable solution.
The idea behind
IPublishedContent
is that it is read-only, (not programmatically, but conceptually). Values are taken from the properties and displayed on the front-end.There was no intention for
IPublishedContent
to be used to write data back to the CMS/database. That's whatIContent
was designed for.I hope this helps?
Cheers,
- Lee
is working on a reply...