Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have created some Razor code to output images onto a page if the exist. It is detailed below and contains some simple checks to prevent rendering a blank list item. The site has gone live and works fine. The client then deleted the image from the media folder within Umbraco, meaning my node had a valid image assigned but the image just didn't exists. I got the following exception:
'string' does not contain a definition for 'crops'
How do I deal with this?
@foreach (dynamic client in @Model.Children)
var image = Model.MediaById(client.Logo);
var crops = image.imageCropper.crops;
@if (crops != null || crops.GetType().ToString() != "System.String")
<img src="@crops.Find("@name", "cropname").url" alt="@client.Name" />
Maybe this post can help you ?
Thanks for the feedback Dave but that was my post! I was struggling with actually using the image cropper in Razor but got it working in the end. Your comment about the helper method only seemed relevant for previous versions of Umbraco Razor where dynamic nodes were not returned. Is that right or would your technique still work?
I'm using this code in a 4.7.1 version of Umbraco and it works there.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted