Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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


  • Martin 241 posts 538 karma points
    4 days ago
    Martin
    0

    Media Picker 2 - Umbraco 7.7 - 'System.Array' does not contain a definition for 'Url'

    Hi All,

    I'm having an issue showing an icon on the multi level navigation.

    I have a property on the document type - "navigationIcon" - which uses the Media Picker 2. I had it working previously on Media Picker 1 with the following code. I understand that Media Picker 2 using the UDI, but Im struggling to get it to work recursively.

    The error message I get is - 'System.Array' does not contain a definition for 'Url'

    Any help would be appreciated.

    Thanks

    Martin

    @foreach (var level2 in childPage.Children.Where("Visible")) {
    <li>
            <a class="cd-nav-item" href="@level2.Url" style="background-image:url('@level2.navigationIcon.Url')">
                <div class="title">@level2.Name</div>
            </a>
    </li>
                            }
    
  • Alex Skrypnyk 3804 posts 13301 karma points mvp
    4 days ago
    Alex Skrypnyk
    0

    Hi Martin

    It looks like on your media picker enabled multiple medias, please check, just turn off multiple choice.

    If you need the possibility to select multiple media, try to use this code:

    @foreach (var level2 in childPage.Children.Where(x => x.IsVisible()))
    {
        var imagesList = level2.GetPropertyValue<IEnumerable<IPublishedContent>>("navigationIcon");
        <li>
            <a class="cd-nav-item" href="@level2.Url" style="background-image:url('@imagesList.FirstOrDefault().Url')">
                <div class="title">@level2.Name</div>
            </a>
        </li>
    }
    

    Read more - https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Media-Picker2

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft