Hi all.
Using Umbraco CMS 10.5.1, we are getting html from a Content node, using ITemplateRenderer.RenderAsync to validate the html.
It fails if we are using a custom controller inherited by RenderController with a custom entity inherited by PublishedContentWrapped.
It does not initiate the RenderController at all. It’s like its looking at the view and decide it cannot bind the models.
using (var stringWriter = new StringWriter())
{
await _templateRenderer.RenderAsync(pageId: 1010, altTemplateId: null, writer: stringWriter);
return stringWriter.ToString();
}
public class ListViewModel : PublishedContentWrapped
{
public ListViewModel(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback) { }
public List<IPublishedContent>? Results { get; set; }
public string? Query { get; set; }
public IHtmlContent? Pagination { get; set; }
}
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ListViewModel>
@{
Layout = "layout.cshtml";
}
<section>
<div>
@await Html.PartialAsync("results", Model)
@if (Model.Pagination != null)
{
@Model.Pagination
}
</div>
</section>
The error we are getting is:
Umbraco.Cms.Web.Common.ModelBinders.ModelBindingException: 'Cannot bind source content type Umbraco.Cms.Web.Common.PublishedModels.PublicationsArea to model type xxx.xxx.xxx.ListViewModel.
The source is a ModelsBuilder type, but the view model is not. The application is in an unstable state and should be restarted.'
Then if we disable the ModelsBuilder, then we get this error:
Umbraco.Cms.Web.Common.ModelBinders.ModelBindingException: 'Cannot bind source content type Umbraco.Cms.Infrastructure.PublishedCache.PublishedContent to model type xxx.xxx.xxx.ListViewModel.'
What are we missing?
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/111970-how-to-use-itemplaterendererrenderasync-with-ipublishedcontentwrapped-served-through-a-rendercontroller