Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 12, 2015 @ 16:38
    Ismail Mayat
    0

    Ditto with MNTP

    So I have a model

        public class DestinationItem
    {
        [TypeConverter(typeof(DittoPickerConverter))]
        public IEnumerable<TravelTip> TravelTips { get; set; }
    }
    

    The property TravelTips in Umbraco is MNTP. That as ditto model looks like

    public class TravelTip
    {
        public IMedia Image { get; set; }
        public RelatedLinks Link { get; set; }
        public string Description { get; set; }
    }
    

    In my code I have

     var currentDestination = Model.Content.As<DestinationItem>();
    

    The travel tips property is always null.

    One more thing Image which is media picker is the type correct or should that be IPublishedContent.

    Regards

    Ismail

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 12, 2015 @ 16:45
    Matt Brailsford
    0

    And your property on the doc type has an alias of "travelTips"?

    IMedia should probably be IPublishedContent I think, or a model of your own if you want ditto to convert it to be strongly typed.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 12, 2015 @ 17:05
    Ismail Mayat
    0

    Yup it does

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 12, 2015 @ 16:45
    Lee Kelleher
    0

    Hi Ismail,

    Hmmm, that "should" work. It could be that Ditto doesn't like the IEnumerable, try changing it to a concrete type, like List<TravelTip>.

    (But I'm sure we try to detect IEnumerable and handle it accordingly).

    With the Image, is IMedia an interface? If so, that would be the same problem, it would need to be a concrete type, so Ditto can create an instance of it.

    Also if it's a media-picker, you'll need to add the type-converter...

    [TypeConverter(typeof(DittoPickerConverter))]
    public IMedia Image { get; set; } // change IMedia to a concrete type
    

    Hope this helps?

    Cheers,
    - Lee

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 12, 2015 @ 17:03
    Ismail Mayat
    0

    I changed IMedia to IPublishedContent no joy

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 12, 2015 @ 17:06
    Lee Kelleher
    0

    Did the List<TravelTip> change work?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 12, 2015 @ 16:48
    Matt Brailsford
    1

    Hehe, you can tell I use umbraco value converters can't you? :) #setandforget

    IEnumberables should be fine.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 12, 2015 @ 16:58
    Lee Kelleher
    0

    Yup!

    @Ismail - if you're cool with dropping the Umbraco Core Property Value Converters package... I'd go with that.

    Although keep in mind that all your MNTPs will return IPublishedContent collections once installed, (you may need to retrofit any existing code).

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 12, 2015 @ 17:04
    Ismail Mayat
    0

    When you saying dropping you mean uninstall it?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 12, 2015 @ 17:05
    Lee Kelleher
    0

    Sorry, I meant "dropping in" - installing (my bad)

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 12, 2015 @ 17:15
    Ismail Mayat
    0

    Lee,

    Its already installed.

    I now have below still no joy

    public class DestinationItem
    {        
        public IEnumerable<TravelTip> TravelTips { get; set; }
    }
    
    public class TravelTip
    {
        public IPublishedContent Image { get; set; }
        public RelatedLinks Link { get; set; }
        public string Description { get; set; }
    }
    

    Regards

    Ismail

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 12, 2015 @ 17:41
    Lee Kelleher
    0

    Hey Ismail,

    I've just tried out mapping to an IEnumerable<T> (in our unit-tests) and it works fine. (So don't worry about my List<T> suggestion.)

    So with your current code, where's it at? Is DestinationItem.TravelTips null, or is it the inner TravelTip items that are null?

    Thanks,
    - Lee

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 13, 2015 @ 07:51
    Ismail Mayat
    0

    The DestinationItem.TravelTips is null if change to IEnumerable

    Regards

    Ismail

  • James Jackson-South 489 posts 1747 karma points c-trib
    Nov 13, 2015 @ 05:08
    James Jackson-South
    100

    Hi Ismail

    Can you try putting the typeconverter attribute on the TravelTip class rather than your property?

    Cheers

    James

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 13, 2015 @ 08:38
    Ismail Mayat
    0

    James,

    That worked a treat, many thanks.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft