More in this section
Forums / Developing with Sitefinity / Adding image to BlogPostList

Adding image to BlogPostList

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Dana
    Dana avatar
    7 posts
    Registered:
    16 Mar 2015
    06 Oct 2015
    Link to this post

    Hi,

     I'm using SF 8.1.5810.0 with Feather and am running in pure MVC mode.  I've added a 'custom field for posts' called "FeaturedImage" as type "Related Media".

     

    I've copied the List.BlogPostList.cshtml and created a custom List.CustomBlogPostList.cshtml.  I'm having trouble getting the image to show.  Here is my code:

    @foreach (var item in Model.Items)
        {
            var navigateUrl = HyperLinkHelpers.GetDetailPageUrl(item, ViewBag.DetailsPageId, ViewBag.OpenInSamePage);

            <div class="row">
                <div class="col-sm-12">
                    <div class="article featured" @Html.InlineEditingAttributes(Model.ProviderName, Model.ContentType.FullName, (Guid) item.Fields.Id)>

                        <img src="@item.Fields.FeaturedImage.MediaUrl" alt="@item.Fields.FeaturedImage.Title" />

                        <a class=" article__title" @Html.InlineEditingFieldAttributes("Title", "ShortText") href="@navigateUrl">@item.Fields.Title</a>

                        <p class="article__excerpt" @Html.InlineEditingFieldAttributes("Summary", "ShortText")>
                            <strong>@item.GetDateTime("PublicationDate", "MMM d, yyyy") - </strong>@Html.Raw(item.Fields.Summary) [...]
                        </p>
                    </div>
                </div>
            </div>

        }

     When I run this, I get this error message:

    Exception occured while executing the controller. Check error logs for details.

    Any suggestions?

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    06 Sep 2017
    13 Oct 2015
    Link to this post
    Hello Dana,

    You can try to add the following code in the custom BlogPostsList template:
    @foreach (var img in item.Fields.FeaturedImage)
    {
       <img src="@img.Fields.MediaUrl" alt="@img.Fields.Title" />
    }    

    I hope this helps.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Dana
    Dana avatar
    7 posts
    Registered:
    16 Mar 2015
    19 Oct 2015 in reply to Svetoslav Manchev
    Link to this post
    That worked! thanks.
3 posts, 0 answered