Copied to clipboard

Flag this post as spam?

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


  • Simon 81 posts 184 karma points
    Dec 09, 2016 @ 12:36
    Simon
    0

    GetCropUrl with MediaPicker

    Hi,

    I'd like to use GetCropUrl along with a MediaPicker. To be honest, I prefer the UI of the MediaPicker as it allows an already-uploaded image to be reused.

    So, I've been following along with this https://umbraco.com/follow-us/blog-archive/2014/5/30/developing-a-website-with-responsive-images-using-the-umbraco-v714-image-cropper/

    However, it doesn't seem to be working for me:

    @{
        var selection = CurrentPage.Site().FirstChild("competitionListing").Children.Where("Visible");
    }
    <ul>
        @foreach(var item in selection){
            <li>
                @{
                    if (item.HasValue("MainImage"))
                    {
                        var typedMedia = Umbraco.TypedMedia(Int32.Parse(item.MainImage));
    
                        <img src="@typedMedia.GetCropUrl(200,200)" />    @*@Umbraco.Content(1129).GetCropUrl("MainImage", "thumbnail")" />*@
                        <pre></pre>
                    }
                }
    
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    Gives me an error:

     'Umbraco.Web.PublishedContentModels.Image' does not contain a definition for 'GetCropUrl'
    

    All I want to be able to do is pick an image through the media picker and then use GetCropUrl to generate different sizes in different views.

    Any ideas?

    Thanks

    Simon

  • Matt Bliss 176 posts 234 karma points c-trib
    Dec 09, 2016 @ 13:30
    Matt Bliss
    0

    Hi Simon,

    There are multiple ways to use the content in Umbraco and at a quick glance the, PublishedContentModels.Image reference looks like you are getting a Models Builder model returned rather than an IPublishedContent which also has the .GetCropUrl method.

    I think you may have a mixture of approaches which is causing your problem.

    What's your @inherits model at the top of your view?

  • Simon 81 posts 184 karma points
    Dec 09, 2016 @ 14:42
    Simon
    0

    Hi Matt,

    It's:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    Many thanks

    Simon

  • Matt Bliss 176 posts 234 karma points c-trib
    Dec 09, 2016 @ 20:09
    Matt Bliss
    0

    Hi Simon,

    I think I can point you in the right direction to investigate then:

    Umbraco.Web.PublishedContentModels.Image is a generated class from ModelsBuilder which takes the 'Image' media type in your database and provides a strongly typed model for it. Look for a file Image.generated.cs to see the generated class (By default it will be in your App_Data folder).

    Have a read of the ModelsBuilder documentation found in these posts which will explain further how the whole system works:

    I suspect you might have the config for models builder in the default mode (PureLive from memory). Obviously, it's difficult to tell from one error without seeing the rest of your site, but I suspect you will need ModelsBuilder in a mode that produces a DLL that you can then reference from anywhere in your code.

    I hope this helps

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft