2012-06-03 89 views
-2

我使用Orchard文档中的guide创建了自定义模块,但出于某种原因,我无法在创建新模块时看到内容类型中的字段。为Orchard创建自定义模块

这是我的模型:

public class CustomerPartRecord : ContentPartRecord 
{ 
    public virtual string FirstName { get; set; } 
    public virtual string LastName { get; set; } 
    public virtual int PhoneNumber { get; set; } 
    public virtual string Address { get; set; } 
    public virtual string Profession { get; set; } 
    public virtual string ProDescription { get; set; } 
    public virtual int Hours { get; set; } 
} 
public class CustomerPart : ContentPart<CustomerPartRecord> 
{ 

    [Required(ErrorMessage="you must enter your first name")] 
    [StringLength(200)] 
    public string FirstName { get { return Record.FirstName; } set { Record.FirstName = value; } } 

    [Required(ErrorMessage = "you must enter your last name")] 
    [StringLength(200)] 
    public string LastName { get { return Record.LastName; } set { Record.LastName = value; } } 

    [Required(ErrorMessage = "you must enter your phone number")] 
    [DataType(DataType.PhoneNumber)] 
    public int PhoneNumber { get { return Record.PhoneNumber; } set { Record.PhoneNumber = value; } } 

    [StringLength(200)] 
    public string Address { get { return Record.Address; } set { Record.Address = value; } } 

    [Required(ErrorMessage = "you must enter your profession")] 
    [StringLength(200)] 
    public string Profession { get { return Record.Profession; } set { Record.Profession = value; } } 

    [StringLength(500)] 
    public string ProDescription { get { return Record.ProDescription; } set { Record.ProDescription = value; } } 

    [Required(ErrorMessage = "you must enter your hours")] 
    public int Hours { get { return Record.Hours; } set { Record.Hours = value; } } 
} 

这是处理程序:

class CustomerHandler : ContentHandler 
{ 
    public CustomerHandler(IRepository<CustomerPartRecord> repository) 
    { 
     Filters.Add(StorageFilter.For(repository)); 
    } 
} 

程序:

class CustomerDriver : ContentPartDriver<CustomerPart> 
{ 
    protected override DriverResult Display(CustomerPart part, string displayType, dynamic shapeHelper) 
    { 
     return ContentShape("Parts_Customer",() => shapeHelper.Parts_Customer(
      FirstName: part.FirstName, 
      LastName: part.LastName, 
      PhoneNumber: part.PhoneNumber, 
      Address: part.Address, 
      Profession: part.Profession, 
      ProDescription: part.ProDescription, 
      Hours: part.Hours)); 
    } 
    //GET 
    protected override DriverResult Editor(CustomerPart part, dynamic shapeHelper) 
    { 
     return ContentShape("Parts_Customer",() => shapeHelper.EditorTemplate(
      TemplateName:"Parts/Customer", 
      Model: part, 
      Prefix: Prefix)); 
    } 
    //POST 
    protected override DriverResult Editor(CustomerPart part, IUpdateModel updater, dynamic shapeHelper) 
    { 
     updater.TryUpdateModel(part, Prefix, null, null); 
     return Editor(part, shapeHelper); 
    } 

迁移:

public class Migrations : DataMigrationImpl 
{ 
    public int Create() 
    { 
     // Creating table CustomerPartRecord 
     SchemaBuilder.CreateTable("CustomerPartRecord", table => table 
      .ContentPartRecord() 
      .Column("FirstName", DbType.String) 
      .Column("LastName", DbType.String) 
      .Column("PhoneNumber", DbType.Int32) 
      .Column("Address", DbType.String) 
      .Column("Profession", DbType.String) 
      .Column("ProDescription", DbType.String) 
      .Column("Hours", DbType.Int32) 
     ); 
     return 1; 
    } 
    public int UpdateFrom1() 
    { 
     ContentDefinitionManager.AlterPartDefinition("CustomerPart", 
      builder => builder.Attachable()); 
     return 2; 
    } 
    public int UpdateFrom2() 
    { 
     ContentDefinitionManager.AlterTypeDefinition("Customer", cfg => cfg 
      .WithPart("CommonPart") 
      .WithPart("RoutePart") 
      .WithPart("BodyPart") 
      .WithPart("CustomerPart") 
      .WithPart("CommentsPart") 
      .WithPart("TagsPart") 
      .WithPart("LocalizationPart") 
      .Creatable() 
      .Indexed()); 
     return 3; 
    } 

} 

有人可以告诉我,如果我错过了什么吗?

回答

0

您是否在placement.info文件中添加了一个条目?我有时会忘记。没有放置,它不会知道把你的内容放在哪里,所以它不会被渲染。

+0

是的,我做了,我把它包含在我的模块的主目录 –

+0

你能看看我的迁移文件吗?我有一种感觉,那里有什么错,可能是我包含的部分太多,或者AlterTypeDefinition有问题 –

+0

放置文件中有什么? –