I have got the PublishedContentModelFactory working nicely. So I have DestinationItem and that has property TravelTips. I also have Destinations item which is parent of DestinationItem and that also has TravelTips property.
What I am doing is
if (currentDestination.TravelTips != null && currentDestination.TravelTips.Any())
{
@Html.Partial("~/Views/Partials/Shared/_TravelTips.cshtml", currentDestination.TravelTips)
}
else
{
var parent = (Destinations)currentDestination.Parent;
if (parent.TravelTips != null && parent.TravelTips.Any())
{
@Html.Partial("~/Views/Partials/Shared/_TravelTips.cshtml", parent.TravelTips)
}
}
In my else statement why do i have todo the cast if i dont then i cannot get TravelTips on parent. Am I missing something?
PublishedContentModelFactory with parent
Guys,
I have got the PublishedContentModelFactory working nicely. So I have DestinationItem and that has property TravelTips. I also have Destinations item which is parent of DestinationItem and that also has TravelTips property.
What I am doing is
In my else statement why do i have todo the cast if i dont then i cannot get TravelTips on parent. Am I missing something?
Regards
Ismail
Hey Ismail,
At that point it's nothing really to do with Ditto, it's a ModelFactory thing.
With the
currentDestination.Parent
the runtime/compiler thinks you're only usingIPublishedContent
, it has no idea of the intended type.You can use the
Parent<T>
extension method, (from the "Umbraco.Web" namespace) to cast it to the intended type (of derivedIPublishedContent
).Hope that helps?
Cheers,
- Lee
is working on a reply...