Copied to clipboard

Flag this post as spam?

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


  • pbl_dk 150 posts 551 karma points
    Mar 12, 2018 @ 17:14
    pbl_dk
    0

    ImageCropper error with macro and partial view

    Hi Forum. I am totally lost. I have tried hundreds of different things. I can not get any output with ImageCropper and Content in a Partial View.

    I have the code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
     var selection = Umbraco.Content(1086).Children().OrderBy("CreateDate desc");
     var numbers = 0;
    }
    
    @foreach (var item in selection)
    {
     if (item.HasValue("newsImage")) {
     <img src="@Url.GetCropUrl(item, propertyAlias: "newsImage", "newsPicture")" />
    }
    }
    

    Visual Studio just returns:

    '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.
    

    How can I get it to work?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 12, 2018 @ 17:17
    Alex Skrypnyk
    100

    Hi Elitenet

    Use this code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var selection = Umbraco.TypedContent(1086).Children().OrderByDescending(x => x.CreateDate);
        var numbers = 0;
    }
    
    @foreach (var item in selection)
    {
        if (item.HasValue("newsImage")) {
            <img src="@Url.GetCropUrl(item, "newsImage", "newsPicture")" />
        }
    }
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 12, 2018 @ 17:18
    Alex Skrypnyk
    1

    The problem is that you are using dynamics, use strongly types instead

  • pbl_dk 150 posts 551 karma points
    Mar 12, 2018 @ 17:33
    pbl_dk
    0

    Thanks Alex!

    Just what I needed.

Please Sign in or register to post replies

Write your reply to:

Draft