'Cannot reference Umbraco generated model

I have an Umbraco 8 site using Models builder and I cannot seem to reference a generated model, as suggested is possible by Umbraco [documentation][1]. My model is

public class BlogPostViewModel : BlogPost
{
    public BlogPostViewModel(IPublishedContent content) : base(content) {  }

    public IList<Comment> Comments { get; set; }
}

In the BlogPostViewModel, the BlogPost reference cannot be found, even if I manually add the Umbraco.Web.PublishedModels namespace.

BlogPost is the Umbraco object and a snippet from the auto-generated class is shown below:

// ctor
    public BlogPost(IPublishedContent content)
        : base(content)
    { }

Has anyone got this model extending mechanism to work? [1]: https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers-v8



Solution 1:[1]

So, found a solution to my problem, posting here in case it helps anyone in the future. The answer was to include in my Visual Studio solution all the .generated.cs classes which Umbraco created in the App_Data/Models folder. This then enabled my custom model (BlogPostViewModel) to be able to inherit from the BlogPost model and I could then add additional data to my custom model and use it in my razor view.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John J Smith