How to access TitlePart of a custom contentpart

Topics: Customizing Orchard, Writing modules
Feb 4, 2013 at 8:18 PM
I have created two custom content types and each contains custom content parts. They also each contain a TitlePart. When I save a new instance of my content type A I need to generate several instances of my content type B. I want content type B's title to use content type A's title concatenated to a key string.

My question is when i am saving content type A in the drivers POST Editor(PartA part, IUpdatModel updater, dynamic shapeHelper) function I don;t know how to gain access of PartA's TitlePart.Title.

I have tried the following

before calling updater.TryUpdateModel(part, Prefix, null, null);
string PartATitle = part.As<TitlePart>().Title; //returns null

after calling updater.TryUpdateModel(part, Prefix, null, null);
string PartATitle = part.As<TitlePart>().Title; //returns null

I also tried getting a reference to the contentmanager and calling
var contentItem = contentManager.Get( part.id ) ;
string PartATitle = part.As<TitlePart>().Title; //returns null

How can I gain access to the Title string of my content part?
Feb 4, 2013 at 9:49 PM
contentItem.As<TitlePart>()
Feb 4, 2013 at 10:10 PM
Hazza wrote:
contentItem.As<TitlePart>()
All I have access to is MyPart and
MyPart.ContentItem.As<TitlePart>().Title returns null
Feb 4, 2013 at 10:53 PM
That should work, are you sure you have added to the TitlePart to the ContentType?
Feb 4, 2013 at 10:59 PM
I am sure because

var temp = MyPart.ContentItem.As<TitlePart>() stores an Orchard.Core.Title.Models.TitlePart in the var temp but temp.Title is null
Feb 4, 2013 at 11:38 PM
Edited Feb 4, 2013 at 11:40 PM
That is very weird, I just tested it now with a random part, worked fine for me.
var pop = part.ContentItem.As<TitlePart>();
var tit = pop.Title;
Edit: I see your problem, it is in your editor method. If you really need to access the TitlePart on edit I think you can overwrite the TitlePart driver
Feb 5, 2013 at 12:09 AM
I will give that a try. Thanks for all of your support. I wish i knew enough about Orchard to help you guys out. But I am learning so maybe in the future.