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?
@using umbraco.MacroEngines;
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.presentation.nodeFactory
@using umbraco.cms.businesslogic.media
<ul>
@foreach (dynamic client in @Model.Children)
{
var image = Model.MediaById(client.Logo);
var crops = image.imageCropper.crops;
<li>
<h2><span>@client.Name</span></h2>
@if (crops != null || crops.GetType().ToString() != "System.String")
{
<span class="itemImage">
<img src="@crops.Find("@name", "cropname").url" alt="@client.Name" />
</span>
}
</li>
}
</ul>