Editor Template - Values not posted to Editor Override

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

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
                .ContentPartRecord()
                .Column("Name", DbType.String)
                .Column("Email", DbType.String)
            );

            // Make the part attachable and add an image field.
            ContentDefinitionManager.AlterPartDefinition("CustomerWithImagePart", part => part
                .Attachable()
                .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

<fieldset>
    <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)
    </div>
    <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)
    </div>
</fieldset>
I have read this discussion where Bertrand suggests an answer:
http://stackoverflow.com/questions/17973022/orchard-custom-field-not-getting-posted-correctly

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

Thanks.
Developer
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
sfmskywalker,

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.
Developer
Mar 13, 2015 at 2:09 PM
Glad I could help.