**嗨,朋友们, 我尝试在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
答案 0 :(得分:0)
正如Bertrand所说,你的类名应该是pascal case以符合C#约定,你传递给CreateTable的表名应该与记录的类名相同。 Orchard负责为您添加最终数据库表的前缀。