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