Last chance to get discounted tickets to Codegarden... Price goes up on Tuesday at 20:00 CEST!

Copied to clipboard

Flag this post as spam?

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

  • Tom Bruce 86 posts 379 karma points
    Jul 13, 2017 @ 09:33
    Tom Bruce

    Hi folks, how do you find image url?

    I have tried drilling down into the properties, I receive a null reference at the following code Udi tempImageUrl = mediaItem.Url;

    Full code below

     public ActionResult RenderFeatured()
            List<FeaturedItem> model = new List<FeaturedItem>();
            IPublishedContent homePage = CurrentPage.AncestorOrSelf(1).DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "home").FirstOrDefault();
            ArchetypeModel featuredItems = homePage.GetPropertyValue<ArchetypeModel>("featuredItems");
            foreach (ArchetypeFieldsetModel fieldset in featuredItems)
                Udi imageId = fieldset.GetValue<Udi>("image");
                var mediaItem = Umbraco.Media(imageId);
                Udi tempImageUrl = mediaItem.Url;
                string imageUrl = tempImageUrl.ToString();
  • Rob Carlaw 19 posts 131 karma points
    Jul 13, 2017 @ 11:34
    Rob Carlaw

    Does that node have a image/ is the node publishd?

    Put a breakpoint and step through it.

    try something like:

    string imageId = fieldset.GetValue<string>("image");
    var mediaItem = Umbraco.Media(imageId);
  • Tom Bruce 86 posts 379 karma points
    Jul 17, 2017 @ 16:08
    Tom Bruce

    Thanks Rob :)

  • Alex Skrypnyk 4468 posts 16007 karma points MVP admin
    Jul 19, 2017 @ 13:23
    Alex Skrypnyk

    Hi Guys

    Be aware that "Umbraco.Media" returns dynamic type object, it's better to use Umbraco.TpyedMedia()



Please Sign in or register to post replies

Write your reply to: