Copied to clipboard

Flag this post as spam?

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


  • Hubert Thalmann 57 posts 263 karma points
    Mar 11, 2021 @ 17:09
    Hubert Thalmann
    0

    Use ImageCropper in dynamic context

    Hello

    I used ImageCropper in a Typed context, but in my case i need it in an dynamic context.

    My Sample Code:

    var mediaItem = blog.Value<IPublishedContent>("blogImage");
     if (mediaItem != null)
     {
         <img src="@Url.GetCropUrl(mediaItem, "Hauptbild")"/>
     }
    

    but MediaItem is null, is Umbraco.ImageCropper not returning IPublishedContent?

    Has anyone a dynamic solution? Thank ins advance.

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Mar 11, 2021 @ 18:27
    Huw Reddick
    0

    I think you need to use

    metiaItem.Url().GetCropUrl("Hauptbild")

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Mar 12, 2021 @ 10:26
    Nik
    1

    Hi Hubert,

    If your blogImage property is an Image Cropper property type, no this does not return an IPublishedContent response, it will be a ImageCropper model (I can't remember it's exact name).

    However, if blogImage is a single media picker, then it should return IPublished Content.

    Can you share a bit more details about what blogImage actually is?

    Cheers

    Nik

  • Hubert Thalmann 57 posts 263 karma points
    Mar 12, 2021 @ 16:35
    Hubert Thalmann
    1

    Thanks for the help, i found it out now:

     var mediaItem = blog.Value<ImageCropperValue>("blogImage");
                                if (mediaItem != null)
                                {
                                    <img src="@[email protected]("Quadrat")"/>
                                }
    
Please Sign in or register to post replies

Write your reply to:

Draft