I have some images in the media storage, and I have a "ProductItem" that has a media picker property "productImage". I've read multiple threads and documentation but nothing seems to work. Just want to display the information of each item, including the image.
Naturally, the first thing I tried was "@product.Value("productImage")", but obviously that didn't work, so I read through many different forum threads and documentation. Either I've done something wrong or the things I read are outdated because I can't seem to display my images. Any help much appreciated!
I read that part of the documentation earlier, but the examples either don't seem to work, or simply doesn't have a good example for my specific use. When inside my loop of product items, applying those methods is very confusing and there isn't much further explanation
I figured the solution would be something along those lines but it throws me an error.
Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'
Calling the Url() method also throws an error
Compiler Error Message: CS1929: 'object' does not contain a definition for 'Url' and the best extension method overload 'PublishedContentExtensions.Url(IPublishedContent, string, UrlMode)' requires a receiver of type 'IPublishedContent'
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 26: @{
Line 27: var media = product.Value<IEnumerable<IPublishedContent>>("productImage");
Line 28: foreach(var item in media)
Line 29: {
Line 30: <img src="@item.Url()"/>
But productImage is the name and each item has an image assigned to it through the media picker so I'm not sure why it's doing this.
Doing this also gives me a NullReferenceException. Seems like it's not finding any published content with this name .. but I definitely did publish it.
For each item, display its image
I have some images in the media storage, and I have a "ProductItem" that has a media picker property "productImage". I've read multiple threads and documentation but nothing seems to work. Just want to display the information of each item, including the image.
Naturally, the first thing I tried was "@product.Value("productImage")", but obviously that didn't work, so I read through many different forum threads and documentation. Either I've done something wrong or the things I read are outdated because I can't seem to display my images. Any help much appreciated!
I'm using the latest version of Umbraco
Hi Ras,
First of all welcome to Our :)
A good place to get an idea how work with the media picker will be this
https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/media-picker/
In the link you will find some good examples on how to get the image via Razor
Hope this helps.
/Dennis
Thanks!
I read that part of the documentation earlier, but the examples either don't seem to work, or simply doesn't have a good example for my specific use. When inside my loop of product items, applying those methods is very confusing and there isn't much further explanation
Hi Ras
One thing you could try is
@product.Value("productImage").Url
Let me know if this works for you or not
/Dennis
I figured the solution would be something along those lines but it throws me an error.
Calling the Url() method also throws an error
Okay
Then you should be able to do the following inside the for each loop
Hope this can help you Ras,
Best,
-Dennis
For some reason the value in
Is null, this is the error I get:
But productImage is the name and each item has an image assigned to it through the media picker so I'm not sure why it's doing this.
Okay Ras, then if i was you then I will try to print out the media variable to see if you get a value or not
So something like @media.Name
Doing this also gives me a NullReferenceException. Seems like it's not finding any published content with this name .. but I definitely did publish it.
Update: Ended up solving it by deleting the productitem template and making a nested element instead, this allowed me to display the image.
is working on a reply...