Copied to clipboard

Flag this post as spam?

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


  • Martin Rud 118 posts 362 karma points c-trib
    May 07, 2021 @ 06:12
    Martin Rud
    0

    "'IPublishedContent' does not contain a definition for 'GetCropUrl'" in my method

    Hi,

    I am creating a method that returns html for a picture element, but gets the below error.

    My code is:

    public static string PictureHtml(string[] srcsets, IPublishedContent image, string classAttr)
    {
        string output = "";
        int i = 1;
    
        foreach (var srcset in srcsets)
        {
            string[] srcsetAttributes = srcset.Split('|');
            if(i != srcsets.Count())
            {
                output += "<srcset src=\"" + image.GetCropUrl(200, 200) + "\" />";
            } else {
                output += "<img src=\"" + image.GetCropUrl(200, 200) + "\" alt=\"" + image.Name + "\" />";
            }
            i++;
        }
    
        return "<picture class=\"" + classAttr + "\">" + output + "</picture>";
    }
    

    Code isnĀ“t finished yet and therefore GetCropUrl parameters are hardcoded to 200.

  • Nik 1439 posts 6318 karma points MVP 4x c-trib
    May 07, 2021 @ 08:40
    Nik
    100

    Hi Martin,

    I think you need to include the Umbraco.Web namespace as GetCropUrl is an extension method.

    Thanks

    Nik

  • Martin Rud 118 posts 362 karma points c-trib
    May 07, 2021 @ 08:42
    Martin Rud
    0

    That works! Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft