IPublishedContent is an interface that describes the key properties of a generic published content item in Umbraco, so you will see there are CreateDate, Id etc properties on your selectedTestimonials.
But that list isn't aware it's a list of Testimonial objects that implement IPublishedContent, which is why you can't see the properties you expect to be available.
You can access properties on an IPublishedContent using .Value<T>("propertyAlias") - but really you'd probably rather they were all Testimonial objects....
which you can achieve by using the .OfType<T>() extension method...
eg
var selectedTestimonials = Umbraco.ContentAtRoot().Where(x => x.IsDocumentType("testimonialList")).FirstOrDefault().Children().OfType<Testimonial>().OrderBy(t => Guid.NewGuid()).Take(10).ToList();
should result in a list of Testimonial objects and give you direct access to the properties.
Unable to use properties of List<IPublishedContent> on view
Hi,
I have a content list wich im getting like this:
var selectedTestimonials = Umbraco.ContentAtRoot().Where(x => x.IsDocumentType("testimonialList")).FirstOrDefault().Children().OrderBy(t => Guid.NewGuid()).Take(10).ToList();
But then i can't use any item properties in the view unless i use a partial that takes the item as the model and inherits from:
Any idea of what im doing wrong? Thanks in advance.
Hi BTrigger
IPublishedContent is an interface that describes the key properties of a generic published content item in Umbraco, so you will see there are CreateDate, Id etc properties on your selectedTestimonials.
But that list isn't aware it's a list of Testimonial objects that implement IPublishedContent, which is why you can't see the properties you expect to be available.
You can access properties on an IPublishedContent using
.Value<T>("propertyAlias")
- but really you'd probably rather they were all Testimonial objects....which you can achieve by using the
.OfType<T>()
extension method...eg
should result in a list of Testimonial objects and give you direct access to the properties.
regards
Marc
Hi Marc,
Works like a charm! Thanks for the great explanation and solution!
Cheers
is working on a reply...