Copied to clipboard

Flag this post as spam?

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


  • Colin McFadden 4 posts 93 karma points
    1 week ago
    Colin McFadden
    0

    Published Models not found - Umbraco 9 on .NET Core

    Hey everyone.

    I'm attempting to build out a simple site on Umbraco 9 and .NET Core, mainly for testing purposes.

    However, PublishedModels is behaving odd. I see the generated models under ~/umbraco/models/, but the razor views do not recognize PublishedModels.XXXX (i.e. @inherits UmbracoViewpage

    Does anyone know what I might be doing wrong? Or where in appsettings to change modelbuilder mode since I don't have web.config?

    I'd appreciate any help.

    EDIT: To be more thorough, the error is "The type for namespace 'Homepage' does not exist in 'Umbraco.Cms.Web.Common.PublishedModels'

  • Bjarke Berg 14 posts 82 karma points hq
    5 days ago
    Bjarke Berg
    0

    Hi Colin..

    There's are few things to notice here: 1) The error you see is expected when using PureLive mode in ModelsBuilder. You should be able to build the solution, even when there are compile-time errors in views, if you have the following setting in the project file (Default when using the Umbraco templates):

    <!--Set this to true ModelsBuilder mode is not PureLive -->
    <PropertyGroup>
        <RazorCompileOnBuild>false</RazorCompileOnBuild>
    </PropertyGroup>
    

    2) The mode of the embedded ModelsBuilder can be changed in any of the JSON files using this code snippet:

    {
      "Umbraco": {
        "CMS": {
          "ModelsBuilder": {
            "ModelsMode": "AppData"
          }
        }
      }
    }
    

    Or you can change it from code, if you expect to use the same mode in all environments, by adding this to your Startup.ConfigureServices

    public void ConfigureServices(IServiceCollection services)
    {
       ...
       services.Configure<ModelsBuilderSettings>(options =>
       {
          options.ModelsMode = ModelsMode.AppData;
       });
    }
    

    BR/ Bjarke Berg

  • james whittington 1 post 71 karma points
    4 days ago
    james whittington
    0

    We had an issue where the models just would not work in the default location. (/umbraco/models), even custom classes we added here could not be discovered.

    You can change the default models location though the configuration settings to see if you are running into the same issue as we did.

     {
      "Umbraco": {
        "CMS": {
          "ModelsBuilder": {
            "ModelsMode": "AppData",
            "ModelsDirectory": "/whatever/path/"
          }
        }
      }
    }
    
  • Bjarke Berg 14 posts 82 karma points hq
    4 days ago
    Bjarke Berg
    0

    Note that the default location is added as type None by default. You will need to add these as Content, like you did in v8, as soon as you use AppData.

    There is an up-for-grabs feature request about writing the Purelive models to another folder, so this folder could be Content by default. https://github.com/umbraco/Umbraco-CMS/issues/10213

Please Sign in or register to post replies

Write your reply to:

Draft