Editor Template - Values not posted to Editor Override

Topics: Administration, Troubleshooting
Mar 11, 2015 at 6:03 PM

I have a part called CustomerWithImagePart and I've added a Media Library Picker Feld through migration.
 // Creating table CustomerWithImagePartRecord
            SchemaBuilder.CreateTable("CustomerWithImagePartRecord", table => table
                .Column("Name", DbType.String)
                .Column("Email", DbType.String)

            // Make the part attachable and add an image field.
            ContentDefinitionManager.AlterPartDefinition("CustomerWithImagePart", part => part
                .WithField("Picture", fld => fld.OfType("MediaLibraryPickerField").WithDisplayName("Customer Picture")));
My driver looks like below:
 protected override DriverResult Display(CustomerWithImagePart part, string displayType, dynamic shapeHelper)
            var mediaPicker = (MediaLibraryPickerField)
                    (from p in part.ContentItem.Parts
                     from field in p.Fields
                     where field.Name == "Picture"
                     select field).FirstOrDefault();

            return ContentShape("Parts_CustomerWithImage", () => shapeHelper.Parts_CustomerWithImage(
                Name: part.Name,
                Email: part.Email,
                ImageURL: mediaPicker.MediaParts.FirstOrDefault().MediaUrl

        protected override DriverResult Editor(CustomerWithImagePart part, dynamic shapeHelper)
           return ContentShape("Parts_CustomerWithImage_Edit", () => shapeHelper.EditorTemplate(
                TemplateName: "Parts/CustomerWithImage",
                Model: part,
                Prefix: Prefix

        protected override DriverResult Editor(CustomerWithImagePart part, IUpdateModel updater, dynamic shapeHelper)
                updater.TryUpdateModel(part, Prefix, new[] { "Picture" }, null);
                return Editor(part, shapeHelper);
The editor template is not posting back values as expected. The template is below.
@model CustomerWithImage.Models.CustomerWithImagePart

    <legend>Customer Fields</legend>
     <div class="editor-label">@Html.LabelFor(x => x.Name)</div>
    <div class="editor-field">
        @Html.EditorFor(x => x.Name)    <br />
        @Html.ValidationMessageFor(x => x.Name)
    <br />
     <div class="editor-label">@Html.LabelFor(x => x.Email)</div>
    <div class="editor-field">
        @Html.EditorFor(x => x.Email)    <br />
        @Html.ValidationMessageFor(x => x.Email)
I have read this discussion where Bertrand suggests an answer:

but I cannot figure out how to implement that solution. Can someone please help?

Mar 12, 2015 at 10:35 PM
Edited Mar 12, 2015 at 10:35 PM
Why are you trying to update the "Image" media library picker field in your driver? That will be handled for you already by the media library picker field driver.
Marked as answer by robroysd on 3/12/2015 at 11:30 PM
Mar 13, 2015 at 7:35 AM
Edited Mar 13, 2015 at 7:36 AM

Thanks a million for your help. The following modification (just one line - exclusion of MediaLibraryPickerField field) fixed the issue.
 protected override DriverResult Editor(CustomerWithImagePart part, IUpdateModel updater, dynamic shapeHelper)
            //updater.TryUpdateModel(part, Prefix, new[] { "Picture" }, null);
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
I did see that the MediaLibraryPickerField has a driver in Orchard.MediaLibrary project. I still didn't understand why inclusion of that property was making the whole post back to editor null all the time.

Haven't seen any articles that clearly say when to include properties on the Editor post back override.

Thanks for your help again.
Mar 13, 2015 at 2:09 PM
Glad I could help.