This is in reference and related to my previous question here.
I am trying to read the Title of the part TitlePart as seen below code:
var query = Services.ContentManager.Query("SideBarLinks").List();
foreach (var sideBarLinks in query)
{
foreach(var part in sideBarLinks.Parts)
{
if (part is Orchard.Core.Title.Models.TitlePart)
{
// Below Line throws error
//string title = part.Title;
}
}
}
Each ContentPart has a title in orchard. So for the TitlePart, Iam trying to read the Title. Also is there any similar property that can be accessed like part.Name ?
Checked the code as well and there is a Public Title property as seen below:

Not all content types have the TitlePart attached. You can check this in your dashboard, and see if your content type has indeed the title part attached to it. For example, the Page content type:
In code you can check like this if the content item has a title part:
The safest and recommended way though to get the display text of a content item, is to use the item metadata:
This has multiple advantages. First one being that you don't have to check for the title part, the method itself will take care of that. Another advantage is that you can override what you want to display as the title. Say you have a Movie content type, and you want the title to be displayed as "Some Movie Title (2001)". The only thing you then have to do is implement the ITitleAspect in your custom part:
The
GetItemMetadata(theMovie).DisplayTextof this item will then return the formatted title;