If you are using the new Media Picker 3 then it no longer returns IPublishedContent but, instead, a new type called MediaWithCrops that then has a property called MediaItem that contains the actual published media content.
So you'd need to change your code to be something like this (not 100% sure):
var fbimage = Model.Value("FacebookImage") == null ? null : Model.Value<MediaWithCrops>("FacebookImage").GetCropUrl(1200,630);
Thanks for the info. Unfortunately MediaWithCrops doesn't have GetCropUrl. I despise crop aliases! I much prefer specifying the crop in code. I started out using cropaliases in Umbraco, and adding/maintaining them was so much more laborious than just specifying .GetCropUrl(W,H) when adding an image to my template.
ImageCropper MediaItem thinks it's null
Model.Value("FacebookImage")
is not null, but I get the below error on the line of code above.What am I missing?
What version of Umbraco are you using?
8.14
If you are using the new
Media Picker 3
then it no longer returnsIPublishedContent
but, instead, a new type calledMediaWithCrops
that then has a property calledMediaItem
that contains the actual published media content.So you'd need to change your code to be something like this (not 100% sure):
var fbimage = Model.Value("FacebookImage") == null ? null : Model.Value<MediaWithCrops>("FacebookImage").GetCropUrl(1200,630);
I've raised this as an issue as it feels like a breaking change, but that is the way it is now. See https://github.com/umbraco/Umbraco-CMS/issues/10397 for the back story.
Thanks for the info. Unfortunately MediaWithCrops doesn't have GetCropUrl. I despise crop aliases! I much prefer specifying the crop in code. I started out using cropaliases in Umbraco, and adding/maintaining them was so much more laborious than just specifying
.GetCropUrl(W,H)
when adding an image to my template.@DanDiplo you were VERY close. Thanks for pointing me in the right direction!!
This works:
is working on a reply...