Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Sep 17, 2016 @ 09:14
    John C Scott
    0

    Nested Content with USiteBuilder

    Just about to add my first ever nested content control and I'm very happy about it.

    There's one potential complication that I'd appreciate any advice on.

    I'm going to do two implementations. One with a set of optional items to add, and first one with a single item which will also be reused in the first implementation. I'll do the second one first as it's hopefully a bit simpler to start with.

    The point of complication is that the site I'm adding it to extensively uses uSiteBuilder and I have to retain this. So document type properties are typically defined as something like:

        [DocumentTypeProperty(UmbracoPropertyType.Other, OtherTypeName = "Multiple Media Picker", Name = "Carousel", Alias = "headerCarousel", Tab = TabNames.Header)]
        public List<int> Carousel { get; set; }
    

    What I'm curious about is what is the best thing to set as the public property for this document type, i.e. the public List< int > part above.

    The site also extensively uses automapper so I will have to try and convert what is returned there into a usable object. Any advice appreciated also on how to best approach that.

    Much obliged!

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 17, 2016 @ 09:21
    Lee Kelleher
    0

    Hi John,

    Well I never thought I'd hear about a combination of NC with uSiteBuilder! :-)

    The return value type from NC is an IEnumerable<IPublishedContent> for multiple values, and an IPublishedContent for a single value.

    uSiteBuilder should be able to wire that up.

    Cheers, - Lee

  • John C Scott 473 posts 1183 karma points
    Sep 17, 2016 @ 09:22
    John C Scott
    0

    You know me. Forever exploring the edge cases!

  • John C Scott 473 posts 1183 karma points
    Sep 17, 2016 @ 09:28
    John C Scott
    0

    Damn (now I'll admit I'm not really a fan of uSiteBuilder) this throws a very annoying error.

    Cannot set the value of a document type property DestinationItemDT.Quote (document type: Umbraco.Core.Models.IPublishedContent) to value: '' (value type: ). Error: Invalid cast from 'System.String' to 'Umbraco.Core.Models.IPublishedContent'.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Exception: Cannot set the value of a document type property DestinationItemDT.Quote (document type: Umbraco.Core.Models.IPublishedContent) to value: '' (value type: ). Error: Invalid cast from 'System.String' to 'Umbraco.Core.Models.IPublishedContent'.
    

    I'll have to see what I can do.

    If I do get the json as a string is there an easy way to convert it back to an IPublishedContent?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 17, 2016 @ 09:50
    Lee Kelleher
    100

    If the string is the serialised JSON, then it'll need to be ran through NC's value converter...

    https://github.com/leekelleher/umbraco-nested-content/blob/master/src/Our.Umbraco.NestedContent/Converters/NestedContentValueConverter.cs

    You'll need to create the NestedContentValueConverter object and call ConvertDataToSource().

    I'm not sure where that code can run, it's been a long time since I've done uSiteBuilder.

    Cheers,
    - Lee

  • John C Scott 473 posts 1183 karma points
    Sep 17, 2016 @ 09:54
    John C Scott
    0

    Thank you - that's perfect!

    I'm using every dignified bone/nerve in my body to stop me saying sarcastic things about having to use usb here. I live in an idealistic universe where I hope by exposing them to the sheer goodness of NC it will broaden their horizons!

  • John C Scott 473 posts 1183 karma points
    Sep 17, 2016 @ 10:47
    John C Scott
    0

    No I gave it a good hour, but couldn't get that to work there. The main issue is getting the PropertyType to pass through. Can't think of any good way of generically doing that, couldn't even quite find a way just to create one of the known correct type.

    Anyway JArray has done the job nicely and happily works with automapper too!

    Thank you again for pointing me in the right directions.

Please Sign in or register to post replies

Write your reply to:

Draft