Copied to clipboard

Flag this post as spam?

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


  • Dmitriy 168 posts 588 karma points
    May 08, 2020 @ 11:21
    Dmitriy
    0

    Intellisense does't recognize models with ModelsBulder AppData mode

    Umbraco 8.6.1, Models Builder embedded

    I using AppData mode for the first time after a long time of Dll mode usage.

    For some reason, Intellisense doesn't recognize any models, whatever I do.

    For example, here is a regular HomePage model, it was included in the project:

    <Content Include="App_Data\Models\HomePage.generated.cs" />
    

    And commonly used in the view:

    @inherits UmbracoViewPage<ContentModels.HomePage>
    @using ContentModels = Umbraco.Web.PublishedModels;
    

    Intellisense doesn't see it and I get compilation errors :(

    What may be wrong?

  • Chris Norwood 131 posts 642 karma points
    May 08, 2020 @ 11:33
    Chris Norwood
    1

    Hi Dmitry

    It looks as if your ContentModels namespace might be incorrect - when I use appdata I usually put my models in a separate "core" class library and I will usually get something like:

    @inherits UmbracoViewPage<ProjectName.Core.Models.Content.ClassName>
    @using ContentModels = ProjectName.Core.Models.ClassName;
    

    In my views - so I would check the namespace in your HomePage.generated.cs class.

  • Dmitriy 168 posts 588 karma points
    May 08, 2020 @ 11:49
    Dmitriy
    0

    I didn't change the standard namespace, it is Umbraco.Web.PublishedModels

    App_Data/Models/HomePage.generated.cs content:

    namespace Umbraco.Web.PublishedModels
    {
    
        [PublishedModel("homePage")]
        public partial class HomePage : PublishedContentModel
        {...}
    }
    
  • Chris Norwood 131 posts 642 karma points
    May 08, 2020 @ 12:07
    Chris Norwood
    1

    Actually I think I've had something like this happen in Visual Studio myself - it sometimes gives loads of errors in the view about namespaces like "System" not being found; usually I can fix it by closing and re-opening the project.

    What happens if you change the first line to

    @inherits UmbracoViewPage<Umbraco.Web.PublishedModels.HomePage>
    

    ?

    I think this can also happen if the namespace isn't specified in the web.config file in the Views directory - something like this should be in there:

      <system.web.webPages.razor>
    
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
          <add namespace="System.Web.Mvc" />
    

    (Can't get the editor to show the whole thing, but

    <add namespace="Umbraco.Web.PublishedModels" />
    

    Should be in the namespaces element)

  • Dmitriy 168 posts 588 karma points
    May 08, 2020 @ 12:41
    Dmitriy
    0
    @inherits UmbracoViewPage<Umbraco.Web.PublishedModels.HomePage>
    

    Nope, didn't help :(

    <add namespace="Umbraco.Web.PublishedModels" />
    

    Checked, has it in /Views/Web.config :(

  • Dmitriy 168 posts 588 karma points
    May 08, 2020 @ 13:31
    Dmitriy
    103

    Got it!

    As a result of VS solution including manipulations (manually too), that node missed from project config (YourUmbracoProjectName.csproj):

    <ItemGroup>
        <Compile Include="App_Data\Models\*.generated.cs" /> <!-- Missing it -->
        <Compile Include="Properties\AssemblyInfo.cs" />
    </ItemGroup>
    

    And seems it is a reason why Intellisense doesn't see it, models not compiled at all.

    The reason I did manual changes in including settings, I wanted my generated models includes automatically to a solution. But it seems VS causes errors when you start to manipulate that folder with UI then.

    So, here is a solution:

    Just add ModelsBuilder folder settings

      <appSettings>
        <add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/App_Code/Models" />
      </appSettings>
    

    Models will be generated to App_Code/Models folder that compiles automatically. I don't sure about performance, but it solves the problem.

Please Sign in or register to post replies

Write your reply to:

Draft