**嗨朋友,我尝试在 Orchard 中创建自定义小部件以显示学生详细信息,它显示在管理面板的小部件列表中,但是当我尝试使用它时单击保存按钮时抛出错误。它显示错误错误是:-
And my code is
Model Code is:-
public class studentPart :ContentPart<studentPartRecord>
{
public string Rollno { get { return Record.Rollno; } set { Record.Rollno =value; } }
public string Name { get { return Record.Name; } set { Record.Name = value; } }
public string Class { get { return Record.Class; } set { Record.Class = value; } }
}
public class studentPartRecord :ContentPartRecord
{
public virtual string Rollno { get; set; }
public virtual string Name { get; set; }
public virtual string Class { get; set; }
}
Migration code is:-
public int Create() {
// Creating table tb_Student_studentPartRecord
SchemaBuilder.CreateTable("tb_Student_studentPartRecord", table =>table
.ContentPartRecord()
.Column("Rollno", DbType.String)
.Column("Name", DbType.String)
.Column("Class", DbType.String)
);
return 1;
}
public int UpdateFrom1()
{
// Creating table tb_EmpData_EmpDataPartRecord
ContentDefinitionManager.AlterPartDefinition(typeof(studentPart).Name,
builder => builder.Attachable());
ContentDefinitionManager.AlterTypeDefinition("StudentWidget",
cfg => cfg
.WithPart("studentPart")
.WithPart("WidgetPart")
.WithPart("CommonPart")
.WithPart("IdentityPart")
.WithSetting("Stereotype", "Widget"));
return 2;
}
Driver code is:-
public class studentPartDriver :ContentPartDriver<studentPart>
{
protected override DriverResult Display(studentPart part, string displayType, dynamic shapeHelper)
{
return ContentShape("Parts_student",
() => shapeHelper.Parts_student(Rollno:part.Rollno,Name:part.Name,Class:part.Class));
}
//GET
protected override DriverResult Editor(studentPart part, dynamic shapeHelper)
{
return ContentShape("Parts_student_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts/student", Model: part, Prefix: Prefix));
}
//POST
protected override DriverResult Editor(studentPart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}
Handler Code is:-
public class studentPartHandler :ContentHandler
{
public studentPartHandler(IRepository<studentPartRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
Filters.Add(new ActivatingFilter<studentPart>("student"));
}
}
Please help me . Thanks in Advance