Copied to clipboard

Flag this post as spam?

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


  • Alex Brown 129 posts 620 karma points
    Apr 16, 2018 @ 11:09
    Alex Brown
    0

    Umbraco.ModelsBuilder.Api Cannot Find Namespace

    Recently I took a look at Umbraco.ModelsBuilder.Api and I wanted to try and create a separate class library to segregate my models.

    I've been following this very helpful guide: https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/

    But I'm a bit stuck. It seems as though ModelsBuilder can't find my generated classes which are in their own library. Here's my WebConfig:

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="Nothing" />
    <add key="Umbraco.ModelsBuilder.EnableApi" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsNamespace" value="Umbraco7102.Library.Models"/>
    <add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/Umbraco7102.Library/Models"/>
    <add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true"/>
    

    /Umbraco7102.Library/Models is where my generated classes are, however I'm being given this message:

    The type or namespace name 'Home' does not exist in the namespace 'Umbraco.Web.PublishedContentModels' (are you missing an assembly reference?)
    

    It throws the error on this line:

    public class _Page_Views_Home_cshtml : Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Home> 
    

    I'm referencing my class library in my Umbraco project, and I've named my generated class builder "UmbracoModels.cs".

    Any help would be much appreciated!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 16, 2018 @ 11:19
    Dave Woestenborghs
    1

    Hi Alex,

    The issue is probably in your view.

    public class _Page_Views_Home_cshtml : Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Home> 
    

    This is pointing to ContentModels namespace

    Can you change your view to start with this statement

    @inherits UmbracoViewPage<Umbraco7102.Libray.Models.Home>
    

    Dave

  • Alex Brown 129 posts 620 karma points
    Apr 16, 2018 @ 11:21
    Alex Brown
    0

    Thanks Dave, that was simple... I think I had tunnel vision

    I feel like a fool.

    Thank you!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 16, 2018 @ 11:24
    Dave Woestenborghs
    0

    No problem...have seen that error myself multiple times.

    dave

  • Alex Brown 129 posts 620 karma points
    Apr 16, 2018 @ 11:36
    Alex Brown
    0

    I noticed something which I think threw me off at first.

    It seems ModelsBuilder removes the period in my class library when generating the models, as they turn out like the following:

    namespace Umbraco7102Library.Models
    {
        /// <summary>File</summary>
        [PublishedContentModel("File")]
        public partial class File : PublishedContentModel
        {
        }
    }
    

    Even though my builder is in the following namespace:

    namespace Umbraco7102.Library.Models
    
  • 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