创建自定义内容部分 Orchard CMS 时出错 [英] Error Creating Custom ContentPart Orchard CMS
问题描述
我收到错误传递到字典中的模型项的类型为‘Orchard.UI.Zones.ZoneHolding’,但该字典需要类型为‘First.Module.Models.PersonListPart’的模型项",当进入管理仪表板内容的编辑器页面时.
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);
}
}
我的 PersonListPart 模型如下所示:
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; }
}
}
它为内容部分加载编辑器 CSHTML,如下所示:
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>
它有一个特别是@model 的问题.
It is having an issue in particular with the @model.
在调试和注释掉@model 时,Model.ContentItem.Part[0] 有这个项目,但我是 Orchard CMS 的新手,我很困惑如何正确使用它.
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.
推荐答案
PersonListPartDriver Editor 方法中存在拼写错误.由于 EditorTemplate() 中的值是动态的,因此很容易创建错字,在这种情况下,它会创建一个难以调试的错误.
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
));
}
修复
Models: part,
应该
Model: part,
这篇关于创建自定义内容部分 Orchard CMS 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!