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:
- Why is the Image shape looking for a MediaPart
- How can I inject the MediaPart as part of the Model? (should I?)
- Should I be creating an alternate view here and drilling down to the correct part?
- Am I completely missing how to use a MediaLibraryPickerField?