Its Version 7.12.3. But I've just realised ive made a massive error, when debugging this the image was coming up as null. Went and check the document type and that particular image field wasn't included :-( :-)
Thanks for the help and making me go into Umbraco and check the version, which lead me to check the Doc Type Properties.
I tried Model.Content previously but it just gave me this error
'System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>' does not contain a definition for 'First' and the best extension method overload 'System.Linq.Enumerable.First<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' has some invalid arguments
Images not displaying in my foreach loop
I have this for each loop which is outputting content fine, it's just my images are not displaying has anyone any ideas why?
Please help :-)
Hi Barry,
What version of Umbraco are you using?
Thanks
Nik
Hi Nik,
Its Version 7.12.3. But I've just realised ive made a massive error, when debugging this the image was coming up as null. Went and check the document type and that particular image field wasn't included :-( :-)
Thanks for the help and making me go into Umbraco and check the version, which lead me to check the Doc Type Properties.
No problem,
Just a couple of bits of feedback, it would best no to use Dynamics if you can avoid it.
So instead of
CurrentPage.AncestorOrSelf(1)
you could doModel.Content.AncestorOrSelf(1)
to get a typed model instead of dynamic.In addition, use
Umbraco.TypedMedia
instead as well.Another thing, 7.12.3 come with Property Value Converters which should (I think) be enabled by default.
So if you go down the typed model route you should be able to do this:
This should in theory get your the media item (assuming one is present still).
When accessing media or content, it's worth adding in a null check as well just to make sure content is still valid.
Hope you don't mind the feedback.
Nik
Thanks for the help.
I tried Model.Content previously but it just gave me this error
Ahh,
Yes that would be because the First function would be wrong in the typed approach.
This is what it would need to change to:
The First expression you'd typed was targeting dynamics so you get the error you saw. This turns the same thing into a typed query in Linq.
Give that a go and see how you get on.
Nik
Is there a missing ) in that Code you sent?
Ahh, yes sorry. Should be a double
))
at the end ofInsurance Tips"
instead of the single that is currently there.Nik
is working on a reply...