I get the error
'IPublishedContent' does not contain a definition for 'metaDescription' and no accessible extension method 'metaDescription' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
The metaDescription property is specific to a doctype, and you're getting IPublishedContent in your loop. So "item" is just an IPublishedContent which cannot know the specific properties you're using.
You either have to go with item.Value("metaDescription") (which is not very desirable due to magic strings) or go with Model.Children<T> where T would be the child nodes' doctype alias, so that "item" is mapped to that specific class in Models Builder that actually contains the metaDescription property.
Getting custom data types from Model.Children
Hi
I'm currently migrating some sites to Umbraco cloud (V7 - v11).
I'm building a landing page that just displays child pages.
Using this code
Within the child pages is a data type called metaDescription, I'd like to display the value from metaDescription in the foreach.
I get the error 'IPublishedContent' does not contain a definition for 'metaDescription' and no accessible extension method 'metaDescription' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
Any ideas how I can do this?
Thanks in advance
The metaDescription property is specific to a doctype, and you're getting IPublishedContent in your loop. So "item" is just an IPublishedContent which cannot know the specific properties you're using.
You either have to go with item.Value("metaDescription") (which is not very desirable due to magic strings) or go with
Model.Children<T>
where T would be the child nodes' doctype alias, so that "item" is mapped to that specific class in Models Builder that actually contains the metaDescription property.Perfect thanks @item.Value("metaDescription") has worked.
is working on a reply...