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 5 posts 95 karma points
    1 week ago
    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 16 posts 128 karma points
    1 week ago
    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 5 posts 95 karma points
    4 days ago
    Tom Bruce

    Thanks Rob :)

  • Alex Skrypnyk 3302 posts 10194 karma points mvp
    1 day ago
    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: