Getting Content Field Values

Topics: Customizing Orchard, General, Writing modules
Dec 27, 2011 at 2:50 PM
Edited Dec 27, 2011 at 2:51 PM

For the project I am working on, I need to be able to find the classification (from the Contrib.Taxonomies module) of a custom content part in order to filter them the way I need to.

 

Migrations.cs

 

public int Create()
{
    SchemaBuilder.CreateTable("NewPartRecord", tbl => tbl
                .ContentPartRecord()
                .Column("AnIntegerRecord")
                .Column("AStringRecord")
            );

    ContentDefinitionManager.AlterPartDefinition("NewPart", prt => prt.WithField.WithField("Classification", fld => fld.OfType("TaxonomyField")));

    ContentDefinitionManager.AlterTypeDefinition("NewType",
                cfg => cfg.WithPart("BodyPart")
                          .WithPart("CommonPart")
                          .WithPart("RoutePart")
                          .WithPart("NewPart")
                          .Creatable());

    return 1;
}

 


 
After creating a piece of content from this content type, I am trying to determine what classification this item belongs to.

 

 

HomeController.cs

 
public ActionResult Index(int wantedTaxonomy)
{
    var parts = new List<ContentPart>();

    foreach (ContentPart part in DemoService.GetStuff())
    {
        //find out what taxonomies part has

        if (taxonomy == wantedTaxonomy)
            parts.Add(part);
    }

    return View(parts);
}
 


The commented portion is where I'm having trouble. I cant seem to find how to access the 
taxonomy field values within the ContentPart.

Any help would be appreciated. Thanks.

 

Coordinator
Dec 27, 2011 at 8:59 PM

shape tracing's Model tab can be pretty helpful for that sort of thing.

Dec 28, 2011 at 2:01 PM

That put me in the right direction. Thank you.