Im having problems getting the cropped images url.
var mediaItem = @CurrentPage.baggrundsbillede;
var file = mediaItem.UmbracoFile;
var croppedUrl = Url.GetCropUrl(mediaItem, "bg");
@mediaItem
@file
@croppedUrl
@mediaItem successfully gives me the Id
@file successfully gives me the url of the original image
@croppedUrl fails and gives me the following error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1973: 'System.Web.Mvc.UrlHelper' has no applicable method named 'GetCropUrl' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
Let's use strongly typed objects and avoid dynamics, I would rewrite your code:
var mediaItem = Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("baggrundsbillede") as Umbraco.Web.PublishedContentModels.Image;
var crop = mediaItem.GetCropUrl("bg");
<img src="@crop">
GetCropUrl problems
Im having problems getting the cropped images url.
@mediaItem successfully gives me the Id
@file successfully gives me the url of the original image
@croppedUrl fails and gives me the following error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1973: 'System.Web.Mvc.UrlHelper' has no applicable method named 'GetCropUrl' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
I've been copying from Umbracos own documentation: https://our.umbraco.org/documentation/getting-started/design/Rendering-Media/
Hi Jon
Try this code:
Read more about image cropper - https://our.umbraco.org/documentation/getting-started/Backoffice/Property-Editors/Built-in-Property-Editors/Image-Cropper#dynamic
Thanks,
Alex
Hi Alex :-)
Your solution doesn't give me the url, but:
1142?mode=pad&rnd=131508709780000000
I've just tried to call the crop:
Which gives me the crop information:
?anchor=center&mode=crop&width=1440&height=900;
...but still no url
What version of Umbraco are you using?
Umbraco version 7.7.1 assembly: 1.0.6471.23325
Hi Jon
Let's use strongly typed objects and avoid dynamics, I would rewrite your code:
Thanks,
Alex
Perfect! Thanks Alex that made it :-D
You are welcome, glad to help you.
Thanks,
Alex
is working on a reply...