Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jon 47 posts 290 karma points
    Sep 26, 2017 @ 07:47
    Jon
    0

    GetCropUrl problems

    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.

    I've been copying from Umbracos own documentation: https://our.umbraco.org/documentation/getting-started/design/Rendering-Media/

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Sep 26, 2017 @ 08:02
    Alex Skrypnyk
    0

    Hi Jon

    Try this code:

    var croppedUrl  = CurrentPage.GetCropUrl("baggrundsbillede", "bg");
    

    Read more about image cropper - https://our.umbraco.org/documentation/getting-started/Backoffice/Property-Editors/Built-in-Property-Editors/Image-Cropper#dynamic

    Thanks,

    Alex

  • Jon 47 posts 290 karma points
    Sep 26, 2017 @ 08:09
    Jon
    0

    Hi Alex :-)

    Your solution doesn't give me the url, but:

    1142?mode=pad&rnd=131508709780000000

    I've just tried to call the crop:

    var crop = file.GetCropUrl("bg");
    

    Which gives me the crop information:

    ?anchor=center&mode=crop&width=1440&height=900;

    ...but still no url

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Sep 26, 2017 @ 08:21
    Alex Skrypnyk
    0

    What version of Umbraco are you using?

  • Jon 47 posts 290 karma points
    Sep 26, 2017 @ 08:41
    Jon
    0

    Umbraco version 7.7.1 assembly: 1.0.6471.23325

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Sep 26, 2017 @ 21:34
    Alex Skrypnyk
    0

    Hi Jon

    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">
    

    Thanks,

    Alex

  • Jon 47 posts 290 karma points
    Sep 27, 2017 @ 08:08
    Jon
    1

    Perfect! Thanks Alex that made it :-D

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Sep 27, 2017 @ 08:22
    Alex Skrypnyk
    0

    You are welcome, glad to help you.

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft