I am having some difficulty retrieving a media ID now that I have upgraded to Umbraco 7.6. I see that in version 8 we are losing a lot of dynamic stuff so I am rebuilding templates to be strongly typed. Is this related to the new GUID being generated for media objects in 7.6+?
In the below code block I can retreive my "bannerimage" property URL In this case a "bannerimage" is an image selected via media picker.
Using the same format and countless others I have tried I can NOT retreive my "attachment" property ID. In this case a .pdf that was selected from a media picker.
I am building a partial view to represent a news post. I have been able to pull all of my other properties from my doc type to include text blocks, formatted dates and images.
Is there some other format needed to pull media that is not specifically an image? Does the file type matter? I understand it should not. It's all just media in the media library, right?
Also, future state I will need video as well. So how might that differ from these media types in the strongly typed model?
Edit: I should include the error.
"System.NullReferenceException: Object reference not set to an instance of an object.
"
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{string imageUrl = Model.Content.GetPropertyValue<IPublishedContent>("bannerimage").Url;
var mediaId = Model.Content.GetPropertyValue<IPublishedContent>("attachment").Id;}
False alarm? I solved my own problem but I spent three days cruising forums on and off before I did so I'm going to post this again to add one more example of how things work in the strongly typed model.
Solution:
I was actually using a multi media picker as opposed to a single media picker and making the call wrongly for that reason.
Retreiving media ID fail in Umbraco 7.6+
Hello,
I am having some difficulty retrieving a media ID now that I have upgraded to Umbraco 7.6. I see that in version 8 we are losing a lot of dynamic stuff so I am rebuilding templates to be strongly typed. Is this related to the new GUID being generated for media objects in 7.6+?
In the below code block I can retreive my "bannerimage" property URL In this case a "bannerimage" is an image selected via media picker.
Using the same format and countless others I have tried I can NOT retreive my "attachment" property ID. In this case a .pdf that was selected from a media picker.
I am building a partial view to represent a news post. I have been able to pull all of my other properties from my doc type to include text blocks, formatted dates and images.
Is there some other format needed to pull media that is not specifically an image? Does the file type matter? I understand it should not. It's all just media in the media library, right?
Also, future state I will need video as well. So how might that differ from these media types in the strongly typed model?
Edit: I should include the error. "System.NullReferenceException: Object reference not set to an instance of an object. "
Thank you for your time.
False alarm? I solved my own problem but I spent three days cruising forums on and off before I did so I'm going to post this again to add one more example of how things work in the strongly typed model.
Solution: I was actually using a multi media picker as opposed to a single media picker and making the call wrongly for that reason.
This link contains the best examples and documentation I have seen thus far regarding working on all things of the strongly typed model: https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/blob/v3/Docs/MultipleMediaPicker.md
Code Solution for multi media picker "enabled box- checked":
is working on a reply...