0
votes

**Hi Friends, I am try to create custom widget in Orchard to display Student detail it show in widget list in admin panel but throw error when click on save button when i try to use it.it shows error error is:-

enter image description here

 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
1
The problems in your code include the fact that your classes don't respect the casing conventions in C# (Pascal-casing) and that the name of your table is not the same as the name of the record class. - Bertrand Le Roy
@BertrandLeRoy : being the beginner of orchard i am lesser familiar with any CMS .Also i don't know about the naming conventions in orchard, if you can please Edit the above code i.e what are the corrections required. - Code Rider
Pascal casing your class names is not an Orchard convention, it's a C# convention. As for the table name, just use the same name as the record class. Use existing modules as examples. - Bertrand Le Roy
@BertrandLeRoy Your are try to say my table name is "tb_Student_studentPartRecord" and my PartRecord class name should be same as table name - Code Rider
Yes, that's what I said twice ;) - Bertrand Le Roy

1 Answers

0
votes
  • Change studentPart to StudentPart
  • Change studentPartRecord to StudentPartRecord
  • Change SchemaBuilder.CreateTable("tb_Student_studentPartRecord" to SchemaBuilder.CreateTable("StudentPartRecord"

As Bertrand says, your class names should be pascal case to comply with C# conventions, and the table name you pass to CreateTable should be the same as the record's class name. Orchard takes care of prefixing the final database table for you.