2013-10-31 53 views
0

**嗨朋友, 我嘗試在Orchard中創建自定義小部件以顯示學生詳細信息,它顯示在管理面板的小部件列表中,但在點擊保存按鈕時拋出錯誤,當我嘗試使用it.it顯示錯誤 錯誤是: -自定義小部件在果園CMS投擲錯誤

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

代碼中的問題包括這樣一個事實,即您的類不尊重C#中的外殼慣例(Pascal-casing),並且您的表的名稱與記錄類的名稱不同。 –

+0

@BertrandLeRoy:作爲果園的初學者,我對任何CMS都不太熟悉。我也不知道果園裏的命名約定,如果可以的話請編輯上面的代碼,即需要什麼樣的更正。 –

+0

Pascal封裝你的類名不是Orchard約定,它是C#約定。至於表名,只需使用與記錄類相同的名稱即可。以現有模塊爲例。 –

回答

0
  • 變化studentPart到studentPart
  • 變化studentPartRecord到studentPartRecord
  • 更改SchemaBuilder.CreateTable(「tb_Student_studentPartRecord」到SchemaBuilder.CreateTable(「StudentPartRecord」

正如伯特蘭德說,你的類名應符合C#約定帕斯卡的情況下,你傳遞給CREATETABLE表名應該與記錄的類名相同。果園爲您處理最終數據庫表的前綴。