Help displaying BlogPost fields

Topics: Customizing Orchard
Apr 12, 2013 at 1:36 PM
Hi, I'm new in Orchard development. I'm trying to display some blogpost fields in a custom shape of a BlogPost, but I can't access to all model namespaces and fields. I learned to show title and a custom field with this code in each post:
string title = post.ContentItem.TitlePart.Title;
DateTime date= post.ContentItem.CommonPart.PublishedUtc;
string introduccion = ((ContentItem)post.ContentItem).Parts.SelectMany(p => p.Fields).Where(f => f.Name == "Introduccion").First().Storage.Get<string>(null);
    
I dont know get Url. I know use @Html.ItemDisplayLink("something", post.ContentItem) to get a html link, but i want get action Url. I tried use post.ContentItem.ContentManager.GetItemMetadata(post) without results.

sorry for my bad english.

Best regards
Developer
Apr 12, 2013 at 11:57 PM
If you want the display url of the blog post, try this:
var displayUrl = Url.ItemDisplayUrl((ContentItem)post.ContentItem);
And, as a free bonus tip, you can get the introduction field value like so:
string introduction = post.ContentItem.BlogPost.Introduccion.Value;
There's a dynamic behavior that is essentially doing what you're doing manually via LINQ.
Apr 15, 2013 at 9:36 AM
Edited Apr 15, 2013 at 12:49 PM
sfmskywalker wrote:
If you want the display url of the blog post, try this:
var displayUrl = Url.ItemDisplayUrl((ContentItem)post.ContentItem);
And, as a free bonus tip, you can get the introduction field value like so:
string introduction = post.ContentItem.BlogPost.Introduccion.Value;
There's a dynamic behavior that is essentially doing what you're doing manually via LINQ.
Thanks! I tuned a bit to get introduction field value:
string introduction = post.ContentItem.BlogPostPart.Introduccion.Value;