Trouble with model updating

Topics: Writing modules
Dec 13, 2011 at 8:23 AM

Hello,

I'm working on custom content part. And I'm having a trouble with saving data from view.
My content part look like this :

namespace Example.Employee.Models
{
    public class EmployeePartRecord : ContentPartRecord
    {
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
        public virtual string Email { get; set; }
    }
}

namespace Example.Employee.Models
{
    public class EmployeePart : ContentPart<EmployeePartRecord>
    {
        public string FirstName
        {
            get { return Record.FirstName; }
            set { Record.FirstName = value; }
        }

        public string LastName
        {
            get { return Record.LastName; }
            set { Record.LastName = value; }
        }
       
        public string Email
        {
            get { return Record.Email; }
            set { Record.Email = value; }
        }
    }
}

Here's my handler

namespace Example.Employee.Handlers
{
    public class EmployeePartHandler: ContentHandler
    {
        public EmployeePartHandler(IRepository<EmployeePartRecord> repository)
        {
            Filters.Add(StorageFilter.For(repository));
        }
    }
}

And this is the driver

namespace Example.Employee.Drivers
{
    public class EployeePartDriver: ContentPartDriver<EmployeePart>
    {
        protected override DriverResult Display(EmployeePart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_Employee",
                                () => shapeHelper.Parts_Employee(
                                    ContentPart: part,
                                    FirstName: part.FirstName,
                                    LastName: part.LastName,
                                    Email: part.Email));
        }

        //GET
        protected override DriverResult Editor(EmployeePart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Employee_Edit",
                                () => shapeHelper.EditorTemplate(
                                    TemplateName: "Parts/Employee",
                                    Model: part,
                                    Prefix: "Employee"
                                    ));
        }

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

View template placed in Views/EditorTemplates/Parts/Employee.cshtml

@model Example.Employee.Models.EmployeePart
<fieldset>
<legend>Employee</legend>
    @Html.LabelFor(model => model.FirstName)
    <div class="editor-field">
        @Html.TextBoxFor(model => model.FirstName)
        @Html.ValidationMessageFor(model => model.FirstName)
    </div>
    @Html.LabelFor(model => model.LastName)
    <div class="editor-field">
        @Html.TextBoxFor(model => model.LastName)
        @Html.ValidationMessageFor(model => model.LastName)
    </div>   
    @Html.LabelFor(model => model.Email)
    <div class="editor-field">
        @Html.TextBoxFor(model => model.Email)
        @Html.ValidationMessageFor(model => model.Email)
    </div>
</fieldset>

Have you any ideas why I couldn't receive data in driver when trying to update the model?

Dec 13, 2011 at 10:30 AM

Problem is solved. Thanks