Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lorenzo 2 posts 72 karma points
    Dec 19, 2022 @ 11:24
    Lorenzo
    0

    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?

  • Luuk Peters 85 posts 331 karma points
    Dec 21, 2022 @ 12:35
    Luuk Peters
    0

    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 :)

  • Lorenzo 2 posts 72 karma points
    Jan 14, 2023 @ 20:21
    Lorenzo
    0

    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.

        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.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies