Copied to clipboard

Flag this post as spam?

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


  • Ajay Karwal 31 posts 149 karma points
    Sep 09, 2015 @ 10:10
    Ajay Karwal
    0

    GetCropUrl and Umbraco.Media

    I have a Partial View which renders a Feature Box on my homepage. These feature boxes are selected via a MNTP on my homepage doctype.

    I'm trying to get the image to display via Image Cropper but keep getting this error.

    The value of parameter 'id' must be either a string or an integer
    

    My Partial View code is

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @*
        This snippet lists the items from a Multinode tree picker, using the pickers default settings.
        Content Values stored as xml.
    
        To get it working with any site's data structure, set the selection equal to the property which has the
        multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
    *@
    
    @{ var selection = CurrentPage.FeaturesToHighlight; }
    
    <div class="feature-boxes">
        <div class="row no-gutter">
    
            @foreach(var item in selection)
            {           
                <div class="col-sm-4">
                    <div class="feature-box">
                        <a href="@item.Link.Url">
                        @{
                            if (item.HasValue("image")) {
                                var featureImage = Umbraco.Media(item.Image);
    
                                <img src="@featureImage.GetCropUrl("featureBox")" alt="" class="img-responsive" />
                            }
                        }
                            <h2>@item.Heading</h2>
                            <p>@item.SubHeading</p>
                        </a>
                    </div>
                </div>
            }
        </div>
    </div>
    

    Some Background Info

    • I've been following along with Jeavon's example in uHangout Ep30.
    • Have changed my Image Media Type from Upload to Image Cropper.
    • Have set a crop called 'featureBox'
    • My media picker alias on my feature box doctype is 'image'

    Can anyone help?

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Sep 09, 2015 @ 10:19
    Steve Morgan
    0

    I'm not sure this is the issue yet but you need to put brackets around the razor that is trying to get the crop URL. e.g.

    <img src="@(featureImage.GetCropUrl("featureBox"))" alt="" class="img-responsive" />
    

    I suspect your actual problem is this line:

    var featureImage = Umbraco.Media(item.Image);
    

    If you comment out the two lines noted and just do:

    <h2>@(item.Image)</h2>  
    

    what is output? If it's not an ID then you need to work on that. Is it a list of IDs - take a look at this if so Media Picker

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Sep 09, 2015 @ 10:21
    Dave Woestenborghs
    101

    Hi Ajay

    Do what does it render when you output

    @item.Image
    

    Maybe you have the Core PropertyValue Convertors package installed : https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters/

    If that's the case item.Image will return the media item instead of the id and you can do this :

    @item.Image.GetCropUrl("featureBox")
    

    Dave

  • Ajay Karwal 31 posts 149 karma points
    Sep 09, 2015 @ 10:31
    Ajay Karwal
    0

    I indeed have got Core Property Value Converters installed.

    Your solution has worked.

    Thank you

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Sep 09, 2015 @ 10:29
    Steve Morgan
    0

    Hi,

    Sorry - just re-read your full post.

    Won't this just work?

        if (item.HasValue("image")) {
    
             <img src="@(item.GetCropUrl("Image", "featureBox"))" alt="" class="img-responsive" />
     }
    
  • Ajay Karwal 31 posts 149 karma points
    Sep 09, 2015 @ 11:01
    Ajay Karwal
    0

    That is what I thought would work too but that renders the image src as

    <img src="Umbraco.Web.Models.DynamicPublishedContent?mode=pad&amp;rnd=130861808530000000" alt="" class="img-responsive">
    

    Dave's solution above has fixed things.

Please Sign in or register to post replies

Write your reply to:

Draft