Adding image to BlogPostList - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Adding image to BlogPostList

  • Adding image to BlogPostList
  • 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?

  • 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
     
  • That worked! thanks.