1
votes

I have a list of blog posts in Orchard CMS. This is my code:

@{
    IEnumerable<object>
    blogPosts = Model.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("blog-posts");
}

<div class="row">
    @foreach (var item in blogPosts)
    {
        <div class="col-md-4 col-sm-6">
            <div>
                <div class="blog-seg post-item seg">
                    <div>@Display(item)</div>
                </div>
            </div>
        </div>
    }
</div>

I want each DIV to have a link to the post. How can I do this?

2
use @Html.ItemDisplayLink(item)Xceno
I have this error: 'System.Web.Mvc.HtmlHelper<dynamic>' does not contain a definition for 'ItemDisplayLink' and the best extension method overload 'Orchard.Mvc.Html.ContentItemExtensions.ItemDisplayLink(System.Web.Mvc.HtmlHelper, Orchard.ContentManagement.IContent)' has some invalid argumentsB-CHI

2 Answers

3
votes

Use the following to display links for content items:

@using Orchard.ContentManagement;

@{
    IEnumerable<dynamic>
        blogPosts = Model.ContentItems.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("blog-posts");
}

<div class="row">
    @foreach (var item in blogPosts) {
        <div class="col-md-4 col-sm-6">
            <div>
                <div class="blog-seg post-item seg">
                    <div>
                        @Html.ItemDisplayLink(item.ContentItem as IContent)
                    </div>
                </div>
            </div>
        </div>
    }
</div>
0
votes
@using Orchard.ContentManagement;
@{
IEnumerable<dynamic>
    blogPosts = Model.ContentItems;
Model.ContentItems.Classes.Add("content-items");
Model.ContentItems.Classes.Add("blog-posts");

}

<div class="row">
@foreach (var item in blogPosts)
{
    IContent contentItem = item.ContentItem;
    var metadata = contentItem.ContentItem.ContentManager.GetItemMetadata(contentItem);
    string alias = metadata.Identity.Get("alias");

    <div class="col-md-4 col-sm-6">
        <div>
            <div class="blog-seg post-item seg">
                <a href="~/@alias" style="display:block;">@Display(item)</a>
            </div>
        </div>
    </div>
}