Jeroen VK
10/05/2023, 8:39 AMD_Inventor
10/05/2023, 10:31 AMD_Inventor
10/05/2023, 10:39 AMdefault.cshtml
view in the blocklist folder. A common approach is to search for a viewcomponent with the same name as the alias of the block type like this:
@inject Microsoft.AspNetCore.Mvc.ViewComponents.IViewComponentSelector selector
@foreach (var block in Model)
{
var data = block.Content;
var contentTypeAlias = data.ContentType.Alias;
if (selector.SelectComponent(contentTypeAlias) != null)
{
@await Component.InvokeAsync(contentTypeAlias, new { model = block })
}
else
{
<partial name="blocklist/grid/@contentTypeAlias" model="@block.Content" />
}
}
Jeroen VK
10/05/2023, 12:25 PM