1
votes

I am getting the error "The model item passed into the dictionary is of type 'Orchard.UI.Zones.ZoneHolding', but this dictionary requires a model item of type'First.Module.Models.PersonListPart'", when entering the editor page for the content in the admin dashboard.

My content driver looks like:

    public class PersonListPartDriver : ContentPartDriver<PersonListPart> 
    {


         protected override DriverResult Display(
             PersonListPart part, string displayType, dynamic shapeHelper) {
             return ContentShape("Parts_PersonList",
                 () => shapeHelper.Parts_PersonList(
                        MaxCount: part.MaxCount
                     ));
         }


         protected override DriverResult Editor(
             PersonListPart part, dynamic shapeHelper) {
             return ContentShape("Parts_PersonList_Edit",
                 () => shapeHelper.EditorTemplate(
                     TemplateName: "Parts/PersonList",
                     Models: part,
                     Prefix: Prefix
));
         }

         //POST
         protected override DriverResult Editor(
             PersonListPart part, IUpdateModel updater, dynamic shapeHelper)
         {

             updater.TryUpdateModel(part, Prefix, null, null);
             return Editor(part, shapeHelper);
         }
     }

My PersonListPart Model looks like:

namespace First.Module.Models {

    public class PersonListPart : ContentPart<PersonListPartRecord> {
        public int MaxCount {
            get { return Record.MaxCount; }
            set { Record.MaxCount = value; }
        }
    }


    public class PersonListPartRecord : ContentPartRecord {
        public virtual int MaxCount { get; set; }
    }
}

It loads the Editor CSHTML for the content part which looks like:

@model First.Module.Models.PersonListPart

<fieldset>
    <legend>@T("Person List Settings")</legend>
    <ol>
        <li>
            @Html.LabelFor(m => m.MaxCount, T("Maximal count"));

            @Html.TextBoxFor(m => m.MaxCount, new { @class = "text small" })
        </li>
    </ol>
</fieldset>

It is having an issue in particular with the @model.

When debugging and commenting out the @model, the Model.ContentItem.Part[0] has the item, but being new to Orchard CMS I am stumped how to use this correctly.

1
What does your PersonListPart look like?Ryan Kelso
@user3123386 added PersonListPart aboveSleepless Ninja

1 Answers

4
votes

There was a typo in the PersonListPartDriver Editor Method. Since the values in the EditorTemplate() are dynamic its easy to create a typo and in this case it created an error that was difficult to debug.

protected override DriverResult Editor(
      PersonListPart part, dynamic shapeHelper) {
          return ContentShape("Parts_PersonList_Edit",
                 () => shapeHelper.EditorTemplate(
                     TemplateName: "Parts/PersonList",
                     Models: part,
                     Prefix: Prefix
      ));
}

The fix

Models: part,

should be

Model: part,