0
votes

I have added a MediaLibraryPickerField to a content type in my migration using this code:

ContentDefinitionManager.AlterPartDefinition("MyPart",
    builder => builder.WithField("MyImage", 
        fieldBuilder => fieldBuilder.OfType("MediaLibraryPickerField")
                                    .WithDisplayName("My Image")));

This gives me a media library picker control in my edit view and works as expected.

When I display MyPart in my SummaryAdmin, Orchard tries to use the Image.SummaryAdmin.cshtml and errors out here because the .As<MediaPart> returns null:

var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();

Model.ContentItem is not a MediaPart, it is a MyType. It does have an ImagePart attached to MyType.

Questions:

  1. Why is the Image shape looking for a MediaPart
  2. How can I inject the MediaPart as part of the Model? (should I?)
  3. Should I be creating an alternate view here and drilling down to the correct part?
  4. Am I completely missing how to use a MediaLibraryPickerField?
1
Can you add more details about what exactly you tried? In particular, I'm not sure what you mean by "when I display MyPart in my SummaryAdmin".Bertrand Le Roy

1 Answers

1
votes
@{  
     var mediaPart= ((Orchard.MediaLibrary.Fields.MediaLibraryPickerField)Model.Fields.Single(f => f.Name == "MyImage")).MediaParts;
}