Copied to clipboard

Flag this post as spam?

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


  • Nancy A. 44 posts 175 karma points
    May 24, 2019 @ 15:31
    Nancy A.
    0

    How to pull in multi media picker items

    Hi, I've created a document type that, along with other properties (single instance), that contains a list of media items from the multi media picker property. When I try pulling data from that specific field, I keep running into issues.

    I'd like to loop through the times that are in that property, but when I do the @foreach on it, it says it doesn't contain the public instance definition of GetENumerator. I tried casting it as an INumerator property but it's not leeting me (

    Here's what I'm doing:

    @model Umbraco.Web.Models.ContentModel
    
    @{
        Layout = "Base.cshtml";
        var photoList = @Model.Content.Value("PhotoAlbumPictures");
    }
    
            @* the fun starts here *@
    
            <div class="container">
                <h3>@Model.Content.Name </h3>
                <h5>@Model.Content.Value("photoAlbumDate")</h5>
                <h5>@Model.Content.Value("photoAlbumSummary")</h5>
                <div class="pic-row">
    
    
                    @foreach (var photo in photoList)
                    {
                    <div class="col-lg-4 col-sm-6 portfolio-item">
                        <div class="card h-100">
                            <a href="@photo.Url" data-lightbox="@photo.Id"><img class="card-img-top" src="@photo.Url" alt="placeholder" /></a>
                            <div class="card-body">
                                <p>
                                    @photo.Url
                                </p>
                            </div>
                        </div>
                    </div>
                    }
    
                </div>
            </div>
    

    I've also tried casting it as an IENumerator field but no luck:

    @{
        Layout = "Base.cshtml";
        IEnumerable<IPublishedContent> photoList = @Model.Content.Value<IEnumerable<IPublishedContent>>("PhotoAlbumPictures");
    }
    

    How do I go making a collection of images from a single multi-image picker field to loop through via Razor in the View? TIA!

  • Nancy A. 44 posts 175 karma points
    May 24, 2019 @ 19:38
    Nancy A.
    0

    I figured it out - found some documentation that referenced to pulling data from a multi-picker property:

    @{
    var aVarName = Model.Content.Value<IEnumerable<IPublishedContent>>("aliasNameOfMultiPicker");
    }
    
    @foreach (var item in aVarName) {
    <a href="@item.Url"><img class="card-img-top" src="@item.Url" alt="placeholder" /></a>
    }
    

    Hopefully this will help someone who is as equally as lost as me.

Please Sign in or register to post replies

Write your reply to:

Draft