MediaLibraryPickerField in custom content type doesn't show

Topics: Customizing Orchard
Feb 6, 2014 at 1:21 PM
I want to programmatically create a content type which includes, among other things, an image. The obvious way to do this seems to be to use a MediaLibraryPickField.

My question is very similar to this one, but unfortunately it doesn't give an answer

My problem is I can't get the field to show up. I've been digging through the docs and other online recourses, but no luck so far. I'm going to post all my code here in the hopes that someone can see what I'm missing. I'm learning, so if I'm doing anything weird, please don't hesitate to point it out.

My content type should consist of:
  • Title
  • Body
  • Description
  • Image
    table => table
        .Column<string>("Description", c => c.Unlimited())

    "MyTypePart", builder => builder
        .WithDescription("Turns content types into a MyType.")
        .WithField("Image", f => f.OfType(typeof(MediaLibraryPickerField).ToString()))

    "MyType",cfg => cfg
public class MyTypePart : ContentPart<MyTypePartRecord>
    public string Description
        get { return Record.Description; }
        set { Record.Description = value; }
public class MyTypePartRecord : ContentPartRecord
    public virtual string Description { get; set; }
public class MyTypePartRecordHandler : ContentHandler
    public MyTypePartRecordHandler(IRepository<MyTypePartRecord> repository) {
public class MyTypeDriver : ContentPartDriver<MyTypePart> {

    public MyTypeDriver() {


    // GET
    protected override DriverResult Display(MyTypePart part, string displayType, dynamic shapeHelper) {
        return ContentShape("Parts_MyType",
            ()=> shapeHelper.Parts_MyType(
                Description: part.Description

    // GET
    protected override DriverResult Editor(MyTypePart part, dynamic shapeHelper)
        return ContentShape("Parts_MyType_Edit",
            () => shapeHelper.EditorTemplate(
                TemplateName: "Parts/MyType",
                Model: part,
                Prefix: Prefix));

    // POST
    protected override DriverResult Editor(MyTypePart part, IUpdateModel updater, dynamic shapeHelper)
        updater.TryUpdateModel(part, Prefix, null, null);
        return Editor(part, shapeHelper);

@model MySolution.Models.MyType

    <div class="editor-label">@T("Description"):</div>
    <div class="editor-field">
        @Html.TextBoxFor(m => m.Description)
        @Html.ValidationMessageFor(m => m.Description)
@using MySolution.Models

<div>Description: @Model.Description</div>

<Place Parts_MyType="Content:1"/>
<Place Parts_MyType_Edit="Content:7.5"/>
Feb 6, 2014 at 1:35 PM
Hi Rikkety,

I'm not sure, but, try to define you part with MediaLibraryPickerField like this
    "MyTypePart", builder => builder
        .WithDescription("Turns content types into a MyType.")
        .WithField("Image", f => f.OfType("MediaLibraryPickerField ").WithSetting("MediaLibraryPickerFieldSettings.Required", "true")))
Marked as answer by Rikkety on 2/10/2014 at 6:09 AM
Feb 7, 2014 at 7:34 AM
Thanks for your suggestion jekay, but unfortunately that didn't work.

I should add that when I inspect the type and part in Content Definition, I can see the field is created, but when i try to create a new item, I can only see the Title, Body and Description fields.
Feb 10, 2014 at 1:09 PM
Edited Feb 10, 2014 at 1:09 PM
I Fixed the issue by doing this in my Migration.cs:
.WithField("Image", f => f.OfType("MediaLibraryPickerField"))
instead of this:
.WithField("Image", f => f.OfType(typeof(MediaLibraryPickerField).ToString()))
which I see now was part of jekay's suggestion, but I only did the "required=true" part earlier, I figured the parameter to OfType would amount to the same thing.