0

**嗨朋友,我尝试在 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
4

1 回答 1

0
  • 将 studentPart 更改为 StudentPart
  • 将 studentPartRecord 更改为 StudentPartRecord
  • 将 SchemaBuilder.CreateTable("tb_Student_studentPartRecord" 更改为 SchemaBuilder.CreateTable("StudentPartRecord"

正如 Bertrand 所说,您的类名应该是帕斯卡大小写以符合 C# 约定,并且您传递给 CreateTable 的表名应该与记录的类名相同。Orchard 负责为您添加最终数据库表的前缀。

于 2013-11-06T13:16:33.597 回答