I'm using Umbraco 7.2.1 and I also have the Umbraco Core Property Value Converters package installed, which seems like it might be relevant.
Here's my code, edited down as it's part of a larger system but this is essentially the process:
UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current); var settings = helper.TypedContent(settingsId);
var logo = settings.GetPropertyValue("logo");
//var logoMedia = Umbraco.TypedMedia(logo.Id.ToString()); // Value of Id visible in intellisense but marked as an error too. Also does this reload the item?
logo is of type 'Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache+DictionaryPublishedContent'. I can see it's the correct item in intellisense but I can't find a way to turn it into a Media item that I can use.
Have you tried just checking what the logo variable gives you if you just render it? @logo - I suspect that it just holds the id so you should be able to write var logoMedia = Umbraco.TypedMedia(logo.ToString());
I'm asuming you're using a media picker somewhere and then the property should just hold the ID without you needing to write logo.Id.
What is this type from a media picker?
I get this type back when retreiving a value back from a media picker.
Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache+DictionaryPublishedContent
I can't seem to turn this into a useable Media item. Any idea how to achieve this?
Hi Jon
How are you trying to render the image? What does your current code look like? Do you mind sharing it? :)
And what is the exact version of Umbraco 7?
/Jan
Hi,
I'm using Umbraco 7.2.1 and I also have the Umbraco Core Property Value Converters package installed, which seems like it might be relevant.
Here's my code, edited down as it's part of a larger system but this is essentially the process:
logo is of type 'Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache+DictionaryPublishedContent'. I can see it's the correct item in intellisense but I can't find a way to turn it into a Media item that I can use.
Hi Jon
Have you tried just checking what the logo variable gives you if you just render it? @logo - I suspect that it just holds the id so you should be able to write var logoMedia = Umbraco.TypedMedia(logo.ToString());
I'm asuming you're using a media picker somewhere and then the property should just hold the ID without you needing to write logo.Id.
/Jan
This is what logo looks like.
Sadly your piece of code doesn't work for me, logoMedia is null.
I presume this is because I have the Umbraco Core Property Value Converters package installed.
But still, what is this type?
I'd rather not uninstall the property value converters, it makes writing Razor code a lot cleaner and less faffy.
Hi Jon
Well when using the value converters the media picker should return IPublishedContent as it says on the package page.
So what you're doing above seems right according to this https://our.umbraco.org/documentation/Reference/Mvc/querying (Don't mind that it says 4.10 - I don't think this has changed in v7).
So do you get anything if you hardcode the id 1103? Just for testing if anything works at all?
/Jan
Hi Jan,
If I hardcode 1103 I get my Media back and I can use it as I'd expect.
var logoMedia = Umbraco.TypedMedia(1103);
I presume this is where you meant me to hard code it?
I don't suppose you've found any way to fix this? I'm a bit lost on what I can possibly do to fix it and it's currently a show stopper.
Edit:
Nevermind, I solved it by using this:
Pretty annoying - I /never/ use var and the one time that I do it all goes tits up!
Hi Jon
No, unfortunately I don't have an idea about what could be the cause currently :-/
/Jan
No worries Jan, see my edit above.
Hi Jon
Aaah, nice - Happy to see you got it all working and thanks for sharing so others can benefit :)
/Jan
is working on a reply...