2011-08-10 82 views
2

我在development.i創建module.when我嘗試保存數據果園模塊新。 我使用此代碼前保存數據果園內容類型爲空

public ActionResult Create(FormCollection input) 
    { 
     var product = contentManager.New<ProductPart>("Product"); 
     product.EmployeeName = input["EmployeeName"]; 
     product.EmployeeFathersName = input["EmployeeFathersName"]; 
     product.DOB = Convert.ToDateTime(input["DOB"]); 
     product.Email = input["Email"]; 
     product.Address = input["Address"]; 
     product.JoiningDate = Convert.ToDateTime(input["JoiningDate"]); 

     if (!ModelState.IsValid) 
     { 
      return View(product); 
     } 

     contentManager.Create(product); 

     return RedirectToAction("Index"); 
    } 

該類我在模型中使用

public class ProductRecord:ContentPartRecord 
{ 
    public virtual string EmployeeName { get; set; } 

    public virtual string EmployeeFathersName { get; set; } 
    public virtual DateTime DOB { get; set; } 
    public virtual string Email { get; set; } 
    public virtual string Address { get; set; } 
    public virtual DateTime JoiningDate { get; set; } 
} 

public class ProductPart : ContentPart<ProductRecord> 
{ 
    /* 
    public int Id 
    { 
     get { return Record.Id; } 
     set{Record.Id = value;} 
    } 
    */ 

    [Required] 
    public string EmployeeName 
    { 
     get { return Record.EmployeeName; } 
     set { Record.EmployeeName = value; } 
    } 

    [Required] 
    public string EmployeeFathersName 
    { 
     get { return Record.EmployeeFathersName; } 
     set { Record.EmployeeFathersName = value; } 
    } 

    [Required] 
    public DateTime DOB 
    { 
     get { return Record.DOB; } 
     set { Record.DOB = value; } 
    } 
    [Required] 
    public string Email 
    { 
     get { return Record.Email; } 
     set { Record.Email = value; } 
    } 
    [Required] 
    public string Address 
    { 
     get { return Record.Address; } 
     set { Record.Address = value; } 
    } 
    [Required] 
    public DateTime JoiningDate 
    { 
     get { return Record.JoiningDate;} 
     set { Record.JoiningDate = value; } 
    } 

} 

我使用的內容類型的「產品」,但是當它進入果園ContentCreateExtension在初級講座方法

public static T New<T>(this IContentManager manager, string contentType) where T : class, IContent { 
     var contentItem = manager.New(contentType); 
     if (contentItem == null) 
      return null; 

     var part = contentItem.Get<T>(); 
     if (part == null) 
      throw new InvalidCastException(); 

     return part; 
    } 

在這裏,我面對的VAR部分爲null,這意味着它的內容部分是空的。
請幫我....

回答

4

你有沒有設置你的遷移類?

public class Migrations : DataMigrationImpl { 

    public int Create() { 
     SchemaBuilder.CreateTable("ProductRecord", 
      table => table 
       .ContentPartRecord() 
       .COLUMNS NEED TO BE SPECIFIED 
      ); 

     ContentDefinitionManager.AlterTypeDefinition("Forum", 
      cfg => cfg 
       .WithPart("ProductPart") 
       .WithPart("CommonPart") 
      ); 

也有你設置你的倉庫?

public class ProductPartHandler : ContentHandler { 
    public ProductPartHandler(IRepository<ProductPartRecord> repository) { 
     Filters.Add(StorageFilter.For(repository)); 
    } 
4

除了尼古拉斯回答,我想提一提,那缺少的驅動程序爲ProductPart可能會導致這樣的錯誤。確保,你至少有空驅動程序定義。

public class ProductPartDriver : ContentPartDriver<ProductPart> {} 
+0

這一個已經燒到了我幾次。 –

2

通過了類似的情況剛走到,確保處理程序類被聲明爲公共。