Copied to clipboard

Flag this post as spam?

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


  • Roger Jarl 5 posts 35 karma points
    4 days ago
    Roger Jarl
    0

    String "nnnn" is not a valid udi

    After upgrading from 7.6.2 to 7.6.3 I get this error: String "1705" is not a valid udi. I have EnablePropertyValueConverters set to true in both 7.6.2 and 7.6.3. My Partial View Macro:

    <div class="row">
    <div class="col-sm-12">
    @foreach (var page in startPage.Children.Where("Visible").Where("showPanel")) {
        <div class="panel">
            <a href="@page.Url">
            <div class="panel-heading">@page.Name</div>
            <div class="panel-body">
                @{
                if (page.HasValue("imgPanel")) {
                <div class="panel-body-image">
                    <img src="@Umbraco.Media(page.imgPanel).Url" alt="" />
                </div>
                }
                }
                <div class="panel-body-text">@page.panelText</div>
            </div>
            </a>
        </div>
    }
    </div>
    

    The error comes from "@Umbraco.Media(page.imgPanel).Url" inside the img tag, because when commenting this row, the code works. Any ideas?

  • Paul Wright (suedeapple) 150 posts 397 karma points
    4 days ago
    Paul Wright (suedeapple)
    0

    Have you tried just...

    <img src="@page.imgPanel.Url" alt="" />
    

    What kind of property editor are you using for "imgPanel" ?

  • Roger Jarl 5 posts 35 karma points
    4 days ago
    Roger Jarl
    0

    @page.imgPanel.Url didn't work. I'm using the Media Picker property editor. I have tried both the obsolete editor and the new one (version 2), without luck.

  • Paul Wright (suedeapple) 150 posts 397 karma points
    4 days ago
    Paul Wright (suedeapple)
    100

    Double check all the child nodes to ensure they have an Image selected.

    I'm guessing your code is passing true on

    if (page.HasValue("imgPanel")) {
    

    You may want to put in an extra NULL check as well

    if (page.imgPanel != null) {
    

    Ensure you are using 7.6.3, and set EnablePropertyValueConverters to true, and use the "version2" media type, and resave all your startPage.children nodes.

    And republish the entire site, to clear out the XML cache

  • Roger Jarl 5 posts 35 karma points
    3 days ago
    Roger Jarl
    0

    Resaving all my startPage.children nodes and republish the entire site did the trick. Thank you!

  • Mike Chambers 562 posts 1061 karma points
    3 days ago
    Mike Chambers
    0

    Was hoping that this issue resolved this, as the republishing any and all pages where we need to alter from the legacy to the new media picker is time consuming on large sites.. Also if a page is in an editing cycle, we can't publish the previous version again to generate the UDI :-(

    http://issues.umbraco.org/issue/U4-9974

    "Plus the media picker is missing a check for the obsolete media picker."

                 public override bool IsConverter(PublishedPropertyType propertyType)
             {
    -            return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPicker2Alias);
    +            if (propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPicker2Alias))
    +                return true;
    +
    +            if (UmbracoConfig.For.UmbracoSettings().Content.EnablePropertyValueConverters)
    +            {
    +                return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPickerAlias);
    +            }
    +            return false;
             }
    
             /// <summary>
    
  • Mike Chambers 562 posts 1061 karma points
    3 days ago
    Mike Chambers
    0

    The source to Object convertor only supports UDI's so no go for legacy ints..

    public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
            {
                if (source == null)
                {
                    return null;
                }
    
                var udis = (Udi[])source;
                var mediaItems = new List<IPublishedContent>();
                if (UmbracoContext.Current == null) return source;
                var helper = new UmbracoHelper(UmbracoContext.Current);
                if (udis.Any())
                {
                    foreach (var udi in udis)
                    {
                        var item = helper.TypedMedia(udi);
                        if (item != null)
                            mediaItems.Add(item);
                    }
                    if (IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias))
                    {
                        return mediaItems;
                    }
                    else
                    {
                        return mediaItems.FirstOrDefault();
                    }
                }
    
                return source;
            }
    

    we could do with a fallback to the

    https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/blob/v3/Our.Umbraco.PropertyConverters/MediaPickerPropertyConverter.cs

    public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
        {
            if (source == null)
            {
                return null;
            }
    
            if (UmbracoContext.Current != null)
            {
                var media = UmbracoContext.Current.MediaCache.GetById((int)source);
                return ConverterHelper.DynamicInvocation() ? media.AsDynamic() : media;
            }
    
            return null;
        }
    
  • Mike Chambers 562 posts 1061 karma points
    1 day ago
    Mike Chambers
    0

    simple workaround...

            if (Model.HasValue("sectionBanner", true))
            {
                IPublishedContent MediaNode;
                try
                {
                    MediaNode = Model.GetPropertyValue<IPublishedContent>("sectionBanner", true);
                }catch
                {
                    // legacy mediapicker stores int not uid so need to fallback
                    MediaNode = Umbraco.TypedMedia(Model.GetProperty("sectionBanner", true).DataValue);
                }
    
                if (MediaNode != null)
                {
    ...
                }
           }
    
Please Sign in or register to post replies

Write your reply to:

Draft