Umb 7.5.11 with Nested Content and Umbraco Property Value Converters installed.
Really stuck trying to get the img url out of this partial. The nested doc type is just a textstring (textOverlay) and a multimediapicker set to pick a single image (slideImage). It all works apart from the img src which is this: @Umbraco.TypedMedia(sliderItem.GetPropertyValue("slideImage")).GetCropUrl("Slider") If I remove .GetCropUrl("Slider") the page displays with the slider working but no image (textOverlay is displayed correctly). If I leave it in then I get a YSOD saying: "System.ArgumentNullException: Value cannot be null. Parameter name: mediaItem"
If I output: sliderItem.GetPropertyValue("slideImage") then I just get a string: "Umbraco.Web.PublishedContentModels.Image" which I understand is from the ModelsBuilder. Stuck.
'object' does not contain a definition for 'GetCropUrl' and the best extension method overload 'Umbraco.Web.ImageCropperTemplateExtensions.GetCropUrl(Umbraco.Core.Models.IPublishedContent, string)' has some invalid arguments
So how to break into the object to get the goodies?
Doing var img = sliderItem.GetPropertyValue<IPublishedContent>("slideImage"); did the trick. I should have thought of trying that cast that to be honest.
Crop Url from Nested Media Picker
Umb 7.5.11 with Nested Content and Umbraco Property Value Converters installed.
Really stuck trying to get the img url out of this partial. The nested doc type is just a textstring (textOverlay) and a multimediapicker set to pick a single image (slideImage). It all works apart from the img src which is this:
@Umbraco.TypedMedia(sliderItem.GetPropertyValue("slideImage")).GetCropUrl("Slider")
If I remove.GetCropUrl("Slider")
the page displays with the slider working but no image (textOverlay is displayed correctly). If I leave it in then I get a YSOD saying: "System.ArgumentNullException: Value cannot be null. Parameter name: mediaItem"If I output:
sliderItem.GetPropertyValue("slideImage")
then I just get a string: "Umbraco.Web.PublishedContentModels.Image" which I understand is from the ModelsBuilder. Stuck.Any advice would be appreciated.
-Craig
Hi
I think with models builder in play you don't need to do the Umbraco.TypedMedia call.
it looks like your call to
sliderItem.GetPropertyValue("slideImage")
is returning an image model.so you should be able to get the crop direct:
personally i would seperate it out a little but the above should work if the values are there.
Thanks Kevin,
Doesn't appear to work though:-
with
@img.GetCropUrl("Slider")
........So how to break into the object to get the goodies?
:(
I have code that gets image and GetCropUrl works -
Image inherits from IPublishedContent so it should let you do that.
if you are not using models builder, you can turn it off in the web.config (set enabled to false).
if you have Core Value Property Converters installed:
change :
to
if not -with model builder off - back to typed content should work.
if you want to use models builder make sure you have core value converters installed - seems to work much nicer when that is in
Doing
var img = sliderItem.GetPropertyValue<IPublishedContent>("slideImage");
did the trick. I should have thought of trying that cast that to be honest.Many thanks :)
is working on a reply...