Copied to clipboard

Flag this post as spam?

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


  • Adamski 2 posts 92 karma points
    Jun 28, 2023 @ 10:39
    Adamski
    0

    How to render multiple media picker items within a blocklist?

    Hi

    New to Umbraco and I want to be able to list a sort of document library using a block list so the user can add a title and then select a number of documents.

    I can display the title, but I'm a bit stuck on how to render the media picker items. I've used this code when having a single document library within a content page setting and was hoping I could just replace the model with the value, but it isn't working as I'm getting:

    cannot convert from 'method group' to 'object?'

    Many thanks

    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
            @{
                var content = (ContentModels.DocumentLibraryList)Model.Content;
            }
    
            <h3>@content.Value("title")</h3>
            <p>
        <h3>@content.Value("title")</h3>
        <p>
            @{var multiMediaPicker = @content.Value("documents");
                if (multiMediaPicker.Count() > 0){
                <h3>Document Library</h3>
                foreach(var item in multiMediaPicker)
                {
                    <li><a href="@item.MediaUrl()">@item.Name</a></li>
                }
               }
            }
            </p>
    
  • Marc Goodson 2157 posts 14435 karma points MVP 10x c-trib
    Jun 28, 2023 @ 12:37
    Marc Goodson
    0

    Hi Adamski

    I'm thinking when you use .Value that's fine for a string, but it's not telling the razor that your property is a more complex thing

    So I wonder if you have

       @{var multiMediaPicker = @content.Value<IEnumerable<MediaWithCrops>>("documents");
    

    whether that bit in the < > brackets will tell the code that it is a list of media items coming back, and therefore .Count() is a valid thing to call...

    regards

    Marc

  • Adamski 2 posts 92 karma points
    Jun 28, 2023 @ 14:24
    Adamski
    100

    Thanks for the reply. However if I try that I get this error:

    The type or namespace name 'MediaWithCrops' could not be found (are you missing a using directive or an assembly reference?) Argument 1: cannot convert from 'method group' to 'object?'

    Edit: I've got it working :-) What I had to do was change it to this:

    var multiMediaPicker = content.Value<IEnumerable<IPublishedContent>>("documents").ToArray();
    

    and add to the top

    @using Umbraco.Cms.Core.Models.PublishedContent
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies