AI OnAI Off
Hi Johan,
Are you using there ContentArea?
In my current project we had simillar issue and ve've resolved it by explicit cast to block type.
Example code:
IEnumerable<ContentAreaItem> contentAreaItems = Enumerable.Empty<ContentAreaItem>(); // your content area items
foreach (var block in contentAreaItems.Select(c => c.GetContent() as IContentData))
{
switch (block)
{
case BlockTypeA blockA:
@Html.PropertyFor(m => blockA)
break;
case BlockTypeB blockB:
@Html.PropertyFor(m => blockB)
break;
case null:
break;
default:
<div>Block not handled.</div>
break;
}
}
We have a temporary fix that seems to work as before but not using PropertyFor but instead calling the View directly using:
@await Html.PartialAsync("SimpleBlock", Model.CurrentBlock.SimpleBlockTypeProperty)
// Or with extra view data...
@await Html.PartialAsync("SimpleBlock", Model.CurrentBlock.SimpleBlockTypeProperty, new ViewDataDictionary(ViewData) { { "cssClass", "some-class" } })
I recently ran into somewhat the same issue - I could not use Html.PropertyFor(x => x.Block) where Block is a actual block instance (rather than a content area or a content link). In my case, I had a dedicated view component for the block, so I just did as below. The error message is very misleading though.
@(await Component.InvokeAsync<SimpleBlockComponent>(new { currentContent = simpleBlock }))
Honestly, I think your solution is fine.
Solution is recently upgraded and we are working through the templates...
It has a simple block type with string and Url properties. It has a View file but no ViewComponent class.
It is used in another block added as local block property, and in that block's view it is called using Html.PropertyFor(x => m.CurrentBlock.SimpleBlockTypeProperty)
We then get this error:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'SimpleBlock_DynamicProxy', but this ViewDataDictionary instance requires a model item of type 'APageViewModel'.
This error is without any custom property renderer.
Anyone solved this or have some pointers?