I'm facing exactly same issue as following page.

Adding mapping to a custom image model in Tridion Reference Implementation

I created a new multimedia schema 'MyImage' and define metadata field on it, and a multimedia link field links to a multimedia component based on it. Then I customized Sdl.Web.DD4T.Mapping.DD4TModelBuilder. I create model class 'MyImage' and added new code to GetMultiMediaLinks() method and added new method GetMyImages(). Now it succeeds to render linked image on a view. But I cannot get metadata value of the multimdeia component because it's not mapped to model property. How can I customize DXA to get metadata of multimedia component linked from multimedia link field?

My DD4TModelBuilder source code is following.

 private static object GetMultiMediaLinks(IEnumerable<IComponent> items, Type modelType, bool multival)
            var components = items as IList<IComponent> ?? items.ToList();
            if (components.Any())
                //Added following code
                if (modelType.IsAssignableFrom(typeof(MyImage)))
                    if (multival)
                        return GetMyImages(components);

                    return GetMyImages(components)[0];
            return null;

        //Added following method
        private static List<MyImage> GetMyImages(IEnumerable<IComponent> components)
            return components.Select(c => new MyImage { Url = c.Multimedia.Url, FileName = c.Multimedia.FileName, FileSize = c.Multimedia.Size, MimeType = c.Multimedia.MimeType }).ToList();

1 Answer 1


I was able to fix this in my solution by creating a custom modelbuilder as well (It's not optimal but I guess this is a workaround until this functionality gets merged into the main source code)

I copied all of the original code of the DD4TModelBuilder.cs in a new class file, and changed the function

private static object GetMultiMediaLinks(IEnumerable<IComponent> items, Type modelType, bool multival){...}


private object GetMultiMediaLinks(IEnumerable<IComponent> items, Type modelType, bool multival){...}

inside this function, i only had to add one line of code : after this if statement

if (modelType.IsAssignableFrom(typeof(Image))){...}

I added this line of code

return GetMultiComponentLinks(items, modelType, multival);

This first processes all OOB schemas image, download and video, and if you have a custom MM schema, it will process this using the functionality used with component links. The resulting object should contain all the MM info (url, size, ...) and the metadata fields defined in your schema.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.