This project is read-only.

Custom fields

Topics: Writing modules
Jun 3, 2012 at 8:41 AM

After completing the writing a module with a text editor tutorial, I wrote another module which is based on the tutorial.

When I open Orchard I see my new module but all the fields for the new model I defined for this module are not showing, although the DB tables were created.

What can be the issue here?   where should I look first in order to find what exactly went wrong?

Jun 3, 2012 at 12:04 PM

(I guess by "fields" you actually mean properties of a content part here, correct? Because fields have another meaning in Orchard.) Make sure you correctly set up your templates, your drivers return the correct shapes using the templates and shapes have a placement defined. Otherwise we could help better if you'd explain what you've done so far and show some code too.

Jun 3, 2012 at 12:25 PM


this is what I have done so far:

the Model:

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")]
        public string FirstName { get { return Record.FirstName; } set { Record.FirstName = value; } }

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

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

        public string Address { get { return Record.Address; } set { Record.Address = value; } }

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

        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; } }


the driver:


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


the migration:


public class Migrations : DataMigrationImpl
        public int Create()
            // Creating table CustomerPartRecord
            SchemaBuilder.CreateTable("CustomerPartRecord", table => table
                .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()
              builder => builder.Attachable());
            return 2;
        public int UpdateFrom2()
            ContentDefinitionManager.AlterTypeDefinition("Customer", cfg => cfg
            return 3;



the view:

@model TimeProject.Models.CustomerPart
    <label class="sub" for="FirstName">First Name</label><br />
    @Html.TextBoxFor(m => m.FirstName, new { @class = "text" })<br />
    <label class="sub" for="LastName">Last Name</label><br />
    @Html.TextBoxFor(m => m.LastName, new { @class = "text" })
I have included the EditorTemplates folder and the parts folder. I did this tutorial with the original names and everything went smooth, I can't find the reason why this doesn't work.

Jun 3, 2012 at 3:05 PM

You forgot the for your Display and Editor shapes.

Something like :


<Place Parts_Customer="Content:5"/>

<Place Parts_Customer_Edit="Content:5"/>


Jun 3, 2012 at 3:24 PM

I did add the file to the module directory. but instead of "Content:5" I put "Content:3" does this matter? I also placed a the proper references in the csproj file 

    <Content Include="Web.config" />
    <Content Include="Views\Web.config" />
    <Content Include="Scripts\Web.config" />
    <Content Include="Styles\Web.config" />
    <Content Include="Properties\AssemblyInfo.cs" />
    <Content Include="" />
    <Content Include="Views\Parts\Customer.cshtml" />
    <Content Include="Views\EditorTemplates\Parts\Customer.cshtml" />
    <Content Include="Module.txt" />
    <Compile Include="Drivers\CustomerDriver.cs" />
    <Compile Include="Handlers\CustomerHandler.cs" />
    <Compile Include="Migrations.cs" />
    <Compile Include="Models\Customer.cs" />
where else should I look? this doesn't make any sense, it supposed to work :)

Jun 3, 2012 at 4:18 PM
Edited Jun 3, 2012 at 4:19 PM
In Driver,  Display : 
Should be:

In Editor :
return ContentShape("Parts_Customer", () => shapeHelper.EditorTemplate(
Should be :
return ContentShape("Parts_Customer_Edit", () => shapeHelper.EditorTemplate(
Jun 3, 2012 at 6:35 PM

thank you, I fixed that and rebuild the solution, but I can't see my Properties yet. do I need to create the module again?

Jun 4, 2012 at 5:56 PM

Anything suspicious in app_data\logs?

Jun 4, 2012 at 7:07 PM

can you please elaborate? where should I look because I don't get any warning or errors during the build process or in debug mode. 

Jun 4, 2012 at 7:42 PM

If something doesn't show up while expected to, it is usually caused by some error happening at runtime. If the error is non-fatal, it is logged and swallowed. If you check the latest log file in the app_data\logs folder, you may find some clues on why the properties aren't showing.

Jun 4, 2012 at 7:51 PM

Thank you, I will check it and try to figure out what went wrong.
By the way I love your tutorial about the adding a module to orchard it helped me to understand the Come better

Jun 4, 2012 at 8:06 PM

Thanks :)