This project is read-only.

How to tell Orchard which namespace to look under for a field

Topics: Writing modules
Dec 19, 2013 at 8:14 PM
I'm building a customer module. The purpose of this module is to create be a data source for subsequent widget modules. I'm creating a "Company" that stores basic data such as address, phone, etc. and I'm running into issues with the field. This field should be able to be included into the subsequent widgets I'll be creating down the road.

The project name that I've created is "Contrib.Company".
It further includes the namespaces and types (I'm hoping per convention):
  • Contrib.Company.Fields
  • Contrib.Company.Fields.CompanyField
  • Contrib.Company.ViewModels
  • Contrib.Company.ViewModels.CompanyFieldViewModel
  • Contrib.Company.Drivers
  • Contrib.Company.Drivers.CompanyFieldDriver
My driver looks like:
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Contrib.Company.ViewModels;

namespace Contrib.Company.Drivers
    public class CompanyFieldDriver : ContentFieldDriver<Fields.CompanyField>
        protected override DriverResult Display(ContentPart part, Fields.CompanyField field, string displayType, dynamic shapeHelper)
            return ContentShape("Fields_Contrib_Company", 
                            s => s.Name(field.Name)          
                            //additional fields

        protected override DriverResult Editor(ContentPart part, Fields.CompanyField field, dynamic shapeHelper)
            var viewModel = new CompanyFieldViewModel
                CompanyID = field.CompanyID,
                CompanyName = field.CompanyName,
                //additional fields

            return ContentShape("Fields_Contrib_Company_Edit",
                            () => shapeHelper.EditorTemplate(
                                TemplateName: "Fields/Contrib.Company.Edit",
                                Model: viewModel,
                                Prefix: GetPrefix(field, part)

        protected override DriverResult Editor(ContentPart part, Fields.CompanyField field, IUpdateModel updater, dynamic shapeHelper)
            var viewModel = new CompanyFieldViewModel();

            if (updater.TryUpdateModel(viewModel, GetPrefix(field, part), null, null))
                field.CompanyID = viewModel.CompanyID;
                field.CompanyName = viewModel.CompanyName;
               //additional fields

            return Editor(part, field, shapeHelper);

        private static string GetPrefix(ContentField field, ContentPart part)
            return (part.PartDefinition.Name + "." + field.Name).Replace(" ", "_");
I can add the field to a content type. But when I go to edit that content type I get the following error:
Compiler Error Message: CS0234: The type or namespace name 'CompanyField' does not exist in the namespace 'Contrib' (are you missing an assembly reference?)
Based on the examples I see from the other modules it should be attempting to look for Contrib.Company.Fields.CompanyField, but it seems to be looking for Contrib.CompanyField.

Please, help, I have no idea what I'm doing wrong.
Dec 19, 2013 at 9:29 PM
Maybe there is a typo in your field editor template razor code.

Marked as answer by TristenAshchi on 12/19/2013 at 1:40 PM
Dec 19, 2013 at 9:42 PM
You were exactly right, just before I read this I did some further digging and it was an issue in my view. I had re-factored the project, so I had to unload the project, update the assembly that was created. And I also needed to update the model reference in my razor view to reflect the correct namespace.

Man, I was beating my head on that issue for hours and could of sworn I updated everything accordingly. Sometimes you need to just step away and look at it with fresh eyes...