Copied to clipboard

Flag this post as spam?

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


  • Rob 3 posts 72 karma points
    Jul 28, 2017 @ 10:35
    Rob
    0

    Accessing custom properties of a media type in Razor

    Hi

    I'm attempting my first production Umbraco website (7.6.4) and have a document type which includes a Media Picker for creating a Image slider.

    Based on the Typed Example code for Media Picker I've got the following code working to display the images in the template.

                    @{
                    var typedMultiMediaPicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("images");
                    foreach (var item in typedMultiMediaPicker)
                    {
                        <div class="item">
                            <img src="@item.Url" alt="">
                            <div class="caption">
                                <div class="box">
                                    <h2>@item.Name</h2>
                                </div>
                            </div>
                        </div>
                    }
                }
    

    However I've also added a custom Dropdown list property to the default Image media type called captionBackgroundColour. If I try to access the property using @item.CaptionBackgroundColour I get Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'CaptionBackgroundColour' and no extension method 'CaptionBackgroundColour' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    Can anyone offer a steer on where I'm going wrong?

Please Sign in or register to post replies

Write your reply to:

Draft