When trying to loop a block list property I get this error (attached image shows more):
An unhandled exception occurred while processing the request.
ModelBindingException: Cannot bind source type Umbraco.Cms.Core.Models.Blocks.BlockListItem`2[[Umbraco.Cms.Web.Common.PublishedModels.SiteBlItem_TextImage, ModelsGeneratedAssembly, Version=0.0.0.2, Culture=neutral, PublicKeyToken=null],[Umbraco.Cms.Core.Models.PublishedContent.IPublishedElement, Umbraco.Core, Version=9.4.3.0, Culture=neutral, PublicKeyToken=null]] to model type Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent.
Umbraco.Cms.Web.Common.ModelBinders.ContentModelBinder.ThrowModelBindingException(bool sourceContent, bool modelContent, Type sourceType, Type modelType)
This is my partial view code:
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@using Umbraco.Cms.Core.Models.Blocks;
@{
var blocks = Model.Value<IEnumerable<BlockListItem>>("ribbons");
foreach (var block in blocks)
{
var content = block.Content;
<h2>@content.Value("headline")</h2>
@await Html.PartialAsync("SiteBlocklist/" + content.ContentType.Alias, block)
}
}
The partials called above does reside in the correct folder (I believe):
Hi Martin,
It's a bit difficult to get you an exact answer without seeing the view for
SiteBlocklist/SiteBlItem_TextImage but on that view, i would expect to see something like the following:
Block list loop gives unhandled error
Hi forum,
When trying to loop a block list property I get this error (attached image shows more):
This is my partial view code:
The partials called above does reside in the correct folder (I believe):
Full error:
Hi Martin, It's a bit difficult to get you an exact answer without seeing the view for SiteBlocklist/SiteBlItem_TextImage but on that view, i would expect to see something like the following:
It seems that view is trying to bind to a different model altogether, say
SiteBlItem_YouTubeVideo
(for example) instead ofSiteBlItem_TextImage
Hope this helps get on track. If not, please post that other view and we'll get it figured out.
Cool! And thanks! That was the solution. :)
In the view for SiteBlocklist/SiteBlItem_TextImage I now have:
is working on a reply...