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
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; }
}
Ditto with MNTP
So I have a model
The property TravelTips in Umbraco is MNTP. That as ditto model looks like
In my code I have
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
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.
Yup it does
Hi Ismail,
Hmmm, that "should" work. It could be that Ditto doesn't like the
IEnumerable
, try changing it to a concrete type, likeList<TravelTip>
.(But I'm sure we try to detect
IEnumerable
and handle it accordingly).With the
Image
, isIMedia
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...
Hope this helps?
Cheers,
- Lee
I changed IMedia to IPublishedContent no joy
Did the
List<TravelTip>
change work?Hehe, you can tell I use umbraco value converters can't you? :) #setandforget
IEnumberables should be fine.
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).When you saying dropping you mean uninstall it?
Sorry, I meant "dropping in" - installing (my bad)
Lee,
Its already installed.
I now have below still no joy
Regards
Ismail
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 myList<T>
suggestion.)So with your current code, where's it at? Is
DestinationItem.TravelTips
null, or is it the innerTravelTip
items that are null?Thanks,
- Lee
The DestinationItem.TravelTips is null if change to IEnumerable
Regards
Ismail
Hi Ismail
Can you try putting the typeconverter attribute on the
TravelTip
class rather than your property?Cheers
James
James,
That worked a treat, many thanks.
Regards
Ismail
is working on a reply...