Copied to clipboard

Flag this post as spam?

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


  • Victor Bjørholm 58 posts 180 karma points
    Jun 17, 2021 @ 09:59
    Victor Bjørholm
    0

    Cant retrieve mediaItem.Value<int>("umbracoHeight") in custom property editor for grid

    I've got this little piece of code, all working fine in a normal view.

     @{
            // The Umbraco Helper has a Media method that will retrieve a Media Item by Id in the form of IPublishedContent, in this example the Media Item has a unique id of 1234:
    
            var mediaItem = Umbraco.Media(1199);
        }
        @if (mediaItem != null)
        {
            // To get the url for your media item, you use the Url property:
            var url = mediaItem.Url;
            // to read a property by alias
            var imageHeight = mediaItem.Value<int>("umbracoHeight");
            var imageWidth = mediaItem.Value<int>("umbracoWidth");
            <img src="@mediaItem.Url" alt="@imageHeight"/>
        }
    

    This code renders everything fine as it should and the image height is displayed in the alt tage in the image. However when trying to use the same code as the renderer for my custom property editor it will not work. It simply does not render the tag on the site. Can not even see it in inspector

Please Sign in or register to post replies

Write your reply to:

Draft