Error Creating Custom ContentPart Orchard CMS

故事扮演 提交于 2019-12-24 18:13:07

问题


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:


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,


来源:https://stackoverflow.com/questions/32592998/error-creating-custom-contentpart-orchard-cms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!