Getting Title from ContentField

Topics: General
Jan 30, 2013 at 1:30 PM

Hi, Please could you explain how I would get the Title value from a ContentField?

Here is my code:

@using Orchard.ContentPicker.Fields
@using Orchard.Utility.Extensions;
@using Orchard.ContentManagement;

    var field = (ContentPickerField) Model.ContentField;
    string name = field.DisplayName;
    var contentItems = field.ContentItems;

    var contentItemPicker = Model.ContentPart.ContentItem as ContentItem;

    @if(contentItems.Any()) {
        foreach(var contentItem in contentItems) {

            var Parts = contentItem.Parts;
            var Title = contentItem.Parts.First(p => p.PartDefinition.Name == "TitlePart");
            var TitleDisplay = contentItem.Parts.SelectMany(p => p.Fields).Where(f => f.Name == "Title").FirstOrDefault();
            @Html.ItemDisplayLink(contentItem) @contentItem.Id 
            if(contentItem != contentItems.Last()) {
    else {
        @T("No content items.")


Jan 30, 2013 at 3:05 PM

I don't believe a ContentPickerField has a Title value, but perhaps I misunderstood the question. Could you rephrase and/or elaborate?


Jan 30, 2013 at 4:49 PM

Hi sfmskywalker, thank you for your reply.

I'm trying to access the contentpicker's related content item's fields. I can see them when I debug and add a watch but can't find a way to access them.

I have a "product" content type that I've linked via a content field to a "category" content type. I'm trying to access the "category's" content type's fields, as besides Title it also includes a category description that I would like to display.

I hope that makes sense, thank you for your help.

Jan 31, 2013 at 1:29 AM
if you put contentItem into a dynamic variable: dynamic item = contentItem; then you can do item.TitlePart.Title
Jan 31, 2013 at 6:30 AM
Hi bertrandleroy, that worked! Thank you very much