Content Part not persisting data

Topics: Writing modules
Jul 7, 2014 at 10:05 PM
Edited Jul 8, 2014 at 12:01 AM
Hi,
I am creating a new Content Part. The content part has been added into a content type.

When editing the content type, I enter some values into the fields of that new content part, however, when debugging I noticed that no values are being submitted into the Driver to update.

What could be the reason? Any specific place to look at?

Below is some code that could help detect the issue:
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace SlideShare.Models
{
    public class SlideSharePartRecord : ContentPartRecord
    {
        public virtual string SlideShareId { get; set; }
        public virtual int StartFromSlide { get; set; }
    }

    public class SlideSharePart : ContentPart<SlideSharePartRecord>
    {
        [Required]
        public string SlideShareId
        {
            get { return Retrieve(x => x.SlideShareId); }
            set { Store(x => x.SlideShareId, value); }
        }

        [Required]
        [Range(1,20)]
        public int StartFromSlide
        {
            get { return Retrieve(x => x.StartFromSlide); }
            set { Store(x => x.StartFromSlide, value); }
        }
    }
}

using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using System;
using System.Collections.Generic;
using SlideShare.Models;

namespace SlideShare.Handlers
{
    public class SlideShareHandler : ContentHandler
    {
        public SlideShareHandler(IRepository<SlideSharePartRecord> repository)
        {
            Filters.Add(StorageFilter.For(repository));
        }
    }
}

using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using SlideShare.Models;
using System;
using System.Collections.Generic;

namespace SlideShare.Drivers
{
    public class SlideShareDriver : ContentPartDriver<SlideSharePart>
    {
        protected override string Prefix { get { return "SlideShare"; } }

        protected override DriverResult Display(SlideSharePart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_SlideShare", () => shapeHelper.Parts_SlideShare(
                            SlideShareId: part.SlideShareId,
                            StartsFromSlide: part.StartFromSlide));
        }

        // GET
        protected override DriverResult Editor(SlideSharePart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_SlideShare_Edit", () => shapeHelper.EditorTemplate(
                    TemplateName: "Parts.SlideShare",
                    Model: part,
                    Prfix: Prefix));
        }

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

@using System.Web.Mvc.Html
@model SlideShare.Models.SlideSharePart

<fieldset>
    <legend>@T("SlideShare Presentation Fields")</legend>

    <div class="editor-field">
        @Html.LabelFor(x => x.SlideShareId, T("SlideShare Id"))
        @Html.EditorFor(x => x.SlideShareId)
        @Html.ValidationMessageFor(x => x.SlideShareId)
    </div>
    <div class="hint">@T("Enter the SlideShare Presentation Id")</div>

    <div class="editor-field">
        @Html.LabelFor(x => x.StartFromSlide, T("Start From Slide"))
        @Html.EditorFor(x => x.StartFromSlide)
        @Html.ValidationMessageFor(x => x.StartFromSlide)
    </div>
    <div class="hint">@T("Enter the Start From Slide")</div>
</fieldset>
Thanks
Bilal