Taxonomies - trying to get to container in TermPart

Topics: Core, Customizing Orchard, General
May 7, 2013 at 9:22 AM
Edited May 7, 2013 at 9:24 AM
Hi There

I am trying to create a breadcrumb using taxonomies.

My issue is that I cant access the Container property with the termPart.
@{
    var terms = (IEnumerable<Orchard.Taxonomies.Models.TermPart>)Model.Terms;
    string name = @Model.ContentField.Name;
    var parent = terms.First().Container.TermPart.Name;
    var link = terms.First().Container.TermPart.Slug;
    
 
}

@if (Model.Terms.Count > 0)
{
    <ul class="breadcrumbs">
        <li><a href="~/articles">Articles</a></li>  
        <li class="divider">&nbsp;</li>
        <li><a href="~/@(link)">@(parent)</a></li>  
        <li class="divider">&nbsp;</li>
        <li>@(new HtmlString(string.Join(", ",
                  terms.Select(t => Html.ItemDisplayLink(t.Name,
                      t.ContentItem).ToString()).ToArray())))</li>
    </ul>

}
If I use shape tracing I see that the properties are in the model.
But I cant access it.

Do I have to cast as Dynamic.

The values I am trying to reach are the following
var parent = terms.First().Container.TermPart.Name;
var link = terms.First().Container.TermPart.Slug;
This is the error I am getting

CS1061: 'Orchard.ContentManagement.IContent' does not contain a definition for 'TermPart' and no extension method 'TermPart' accepting a first argument of type 'Orchard.ContentManagement.IContent' could be found (are you missing a using directive or an assembly reference?)


Any suggestions

Thanks
Stanton
Developer
May 7, 2013 at 2:02 PM
Edited May 7, 2013 at 2:02 PM
Assuming the Container has a TermPart attached, you can access it by casting the Container to dynamic, or by using the .As<T>() extension method to "cast" the Container to TermPart.