Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Leo 10 posts 103 karma points
    Nov 17, 2015 @ 10:32
    Leo
    0

    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!

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Nov 19, 2015 @ 09:50
    Lee Kelleher
    0

    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

  • Leo 10 posts 103 karma points
    Nov 25, 2015 @ 12:08
    Leo
    0

    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?

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Nov 25, 2015 @ 12:18
    Lee Kelleher
    1

    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 what IContent was designed for.

    I hope this helps?

    Cheers,
    - Lee

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies