Models Builder GetModelContentType() in Umbraco 11
I am in the process of migrating my Umbraco 8 site to 11, when I generate my models and try to use the GetModelContentType() static extension method in some of my views, like I was doing on 8 and like it is shown on the new docs for the example TextPage generated model
var contentType = TextPage.GetModelContentType(); // is a PublishedContentType
I get an error, as the method is expecting the IPublishedSnapshotAccessor parameter.
There is no argument given that corresponds to the required formal parameter 'publishedSnapshotAccessor' of 'HomePage.GetModelContentType(IPublishedSnapshotAccessor)'
Am I missing an additional reference or namespace I need to add?
I'm curious what you are trying to do. Why do you need the model content type? I'm asking, because maybe there is a different way to achieve what you want to do :)
I know this is really old now, I have not had the chance to come back to this for quite a long time. I was trying to use the GetByContentType method from the IPublishedContentCache, that takes a IPublishedContentType as a parameter. The following code is what was working for me in Umbraco 8.
using (var umbContextReference = _umbContextFactory.EnsureUmbracoContext())
{
IPublishedContentCache content = umbContextReference.UmbracoContext.Content;
var sessions = content.GetByContentType(Schedule.GetModelContentType()).ToList();
...
}
You can use it now if you inject the IPublishedSnapshotAccessor and then pass it as a parameter.
Models Builder GetModelContentType() in Umbraco 11
I am in the process of migrating my Umbraco 8 site to 11, when I generate my models and try to use the GetModelContentType() static extension method in some of my views, like I was doing on 8 and like it is shown on the new docs for the example TextPage generated model
I get an error, as the method is expecting the IPublishedSnapshotAccessor parameter.
Am I missing an additional reference or namespace I need to add?
I'm curious what you are trying to do. Why do you need the model content type? I'm asking, because maybe there is a different way to achieve what you want to do :)
Hi Luuk,
I know this is really old now, I have not had the chance to come back to this for quite a long time. I was trying to use the GetByContentType method from the IPublishedContentCache, that takes a IPublishedContentType as a parameter. The following code is what was working for me in Umbraco 8.
You can use it now if you inject the IPublishedSnapshotAccessor and then pass it as a parameter.
is working on a reply...