Copied to clipboard

Flag this post as spam?

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


  • Kyle 4 posts 74 karma points
    Feb 15, 2021 @ 15:31
    Kyle
    0

    Using my own Models not working

    Hi Matt,

    I have tested the method of creating my own Models, and seem to be running into a number of issues. Web Config Dll as a model mode is not used on Umbraco 8.5+. Error Below i am adding a type to the contact page template. And it seems to be grabbing a old model rather than the one generated. Page Compositions Contact code

    This would be a shame if we were to scrap the Amplify theme and create another from scratch.

    Running Umbraco 8.10

  • Alex Skrypnyk 5978 posts 22689 karma points MVP 4x admin c-trib
    Feb 15, 2021 @ 19:31
    Alex Skrypnyk
    0

    Hi Kyle

    Did you build Models? Try to go to Umbraco backend -> Settings -> Build Models

    Thanks, Alex

  • Kyle 4 posts 74 karma points
    Feb 15, 2021 @ 20:10
    Kyle
    0

    Hi Alex, yes models have been rebuilt and generated multiple times and keep getting the same errors as the screenshot shown.

    All im trying to do is edit a certain page. So in this case contact and add a "Article Image" as a doc type but the model is being generated and upto date but it won't let me call it unless I include that file.And including it breaks the site.

  • Neil Hodges 329 posts 935 karma points
    Feb 16, 2021 @ 09:15
    Neil Hodges
    0

    Hey Alex

    Kyle works with me, and we're running into problems with using the Amplify theme.

    So using it we have followed the instructions from Amplifys download page to install the UmbracoModelsBuilder and Umbraco.ModelsBuilder.Ui even tho we are using a 8.10 version of Umbraco.

    I was under the impression DLL mode was not used in Umbraco 8 anymore, so our first question is, do we still need to install Umbraco.ModelsBuilder and Umbraco.ModelsBuilder.Ui with Amplify theme? Doing so and setting it to DLL mode causes the Boot Failure. Setting it back to PureLive or AppData allows the site to come back up.

    But that leads to the Model generation problem. ASP.NET Temp files are saying it cant find refrence to the generated Models.

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 16, 2021 @ 11:40
    Matt Barlow | jacker.io
    0

    The full version of modelsbuilder was removed from Umbraco. It's now separate nuget packages.

    To use Dll mode you need to include those nuget packages. Then build models via the back office. It will just replace the generated files inside the App_Data/Models folder and compile them into the Umbraco.Web.PublishedModels.dll.

    Alternatively, you can clone source code and use that, as that contains all of the code and additional functionality. Then you can decide on whatever models builder mode you want, and it will work with AppData mode.

  • Neil Hodges 329 posts 935 karma points
    Feb 16, 2021 @ 12:12
    Neil Hodges
    0

    Hi Matt

    Ok just followed that above.

    Installed Umbraco.ModelsBuilder & Umbraco.ModelBuilder.Ui into the site via NuGet and rebuilt in visual studio.

    Changed to Dll mode in web.config.

    Went to Generate Models in back office, then Umbraco crashes and i see the boot failed screen as above?

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 16, 2021 @ 12:16
    Matt Barlow | jacker.io
    0

    Can you make sure that the models in App_Data/Models are excluded from the project.

  • Neil Hodges 329 posts 935 karma points
    Feb 16, 2021 @ 12:19
    Neil Hodges
    0

    Yep, tried that, but now a new error:

    enter image description here

    Seems to be a roundabout situation we keep on getting into, one thing leads to another. Not sure why Amplify being referenced in the Models is not being picked up?

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 16, 2021 @ 12:21
    Matt Barlow | jacker.io
    1

    you need to exclude that models folder, I can see that it's included.

  • Neil Hodges 329 posts 935 karma points
    Feb 16, 2021 @ 12:32
    Neil Hodges
    0

    That's got it Matt.

    I think we were getting into a loop with AppData and Dll

    We wanted the intellisense and i think not having the ModelsBuilder from the start was causing the problem.

    So now moving the we.config to AppData generating the Models should be able to be added to the project to pick up the IntelliSense when trying to pick up the strongly typed models in our views?

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 16, 2021 @ 12:39
    Matt Barlow | jacker.io
    1

    Okay, if you add the views folder to the solution you should have the intellisense.

    Like I say though, probably best to just clone the sourcecode, so you have all of the uncompiled code.

  • Neil Hodges 329 posts 935 karma points
    Feb 16, 2021 @ 12:46
    Neil Hodges
    0

    No worries, thanks for your help on it, We'll crack on with it, and thanks again for the Amplify theme.

    We'll be making a donation going forward as we'd like to use it for some up-and-coming work.

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 16, 2021 @ 13:12
    Matt Barlow | jacker.io
    0

    Cool, thanks, also the front-end code is also available here: https://github.com/mjbarlow/amplify-umbraco-frontend

  • Robert Freeland 18 posts 90 karma points
    Feb 17, 2021 @ 14:36
    Robert Freeland
    0

    Hey Matt great job with Amplify!! I have decided to have a look at it and I have 2 questions. I have used the Article/Articles as a Template for a Blog section. They are identical in that one was used as a template for the other. On my new Blog/BlogPost model I am having issues getting the Sidenav to work. It complains that model has no property for Sidenav? ie.. Model.SideNav().HasValue() generates an exception. Obviously this has something to do with models, but I seem to have no issues with any other properties in the model. Any thoughts??

  • Neil Hodges 329 posts 935 karma points
    Feb 17, 2021 @ 14:46
    Neil Hodges
    0

    Hey Robert

    Can you share your code? A screenshot?

    We've just been debugging a Block List, we may be able to help :)

  • Robert Freeland 18 posts 90 karma points
    Feb 17, 2021 @ 15:06
    Robert Freeland
    0

    Neil, It fails to recognize the definition of 'SideNav' for my Model when referencing this:

            @if (Model.SideNav().HasValue() && !Model.HideSideNavs)
            {
                <div class="column is-2-tablet">
                    <aside class="menu amplify-menu">
                        <h4 href="@Model.Url()" class="menu-label has-text-weight-semibold amplify-menu-link">
                            <span>@Umbraco.GetDictionaryValue("Blogpost.Contents")</span>
                        </h4>
                        <a class="menu-label has-text-weight-semibold amplify-menu-header has-text-link">
                            <span>@Umbraco.GetDictionaryValue("Blogpost.Contents")</span>
                        </a>
                        <ul class="menu-list amplify-menu-list">
                            @foreach (var navItem in Model .SideNav())
                            {
                                <li><a href="#@navItem.url">@navItem.name</a></li>
                            }
                        </ul>
                    </aside>
                </div>
            }
    

    I'm using the exact same Compositions as the Article Document type, in fact everything is the same. Just cannot seem to get it to recognize 'SideNav'. Any help would be appreciated.

  • Neil Hodges 329 posts 935 karma points
    Feb 17, 2021 @ 15:55
    Neil Hodges
    0

    Ok, I might be stating the obvious here so please excuse me.

    If you can re-build your Models from the Settings > ModelsBuilder and then see if it brings up the SideNav

    Double-check the alias name of the SideNav you are trying to access from the Document Type / Property Type.

    Then if you can load a breakpoint on the Model to see if other properties of that Document Type are being pulled through Ok?

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 17, 2021 @ 17:00
    Matt Barlow | jacker.io
    0

    If you want to extend the models:

    https://our.umbraco.com/documentation/reference/templating/modelsbuilder/Understand-And-Extend

    All custom extensions to the models are in the AppData/Models/Amplify.cs file.

  • Robert Freeland 18 posts 90 karma points
    Feb 17, 2021 @ 18:16
    Robert Freeland
    0

    Matt, I did extend the Models in the _Amplify.cs file to accomodate my Blogpost Model EXACTLY the same way you had the extensions setup for Article but when I include the _Amplify.cs file to make these changes I get a whole host of other compile issues and if I don't include it then it doesn't see my changes. Am I missing something else perhaps?

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 17, 2021 @ 18:40
    Matt Barlow | jacker.io
    0

    Hmm, okay, are you using the source code from github or the installed package?

    Also can you put the error message you are receiving here?

  • Robert Freeland 18 posts 90 karma points
    Feb 17, 2021 @ 18:53
    Robert Freeland
    0

    Installed Package Source. Here is the changed version of _Amplify.cs in the Models folder.

    using System; using System.Collections.Generic; using System.Linq; using Umbraco.Core;

    namespace Umbraco.Web.PublishedModels { #region IIsContentPage public interface IIsContentPage { bool IsContentPage { get; set; } } public partial class BannerStripSection : IIsContentPage { public bool IsContentPage { get; set; } } public partial class BannerStripComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class Gallery : IIsContentPage { public bool IsContentPage { get; set; } } public partial class GalleryComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class ShareLinks : IIsContentPage { public bool IsContentPage { get; set; } } public partial class ShareLinksComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class Slider : IIsContentPage { public bool IsContentPage { get; set; } } public partial class SliderComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class UmbracoFormItem : IIsContentPage { public bool IsContentPage { get; set; } } public partial class UmbracoFormComponent : IIsContentPage { public bool IsContentPage { get; set; } } public partial class Video : IIsContentPage { public bool IsContentPage { get; set; } } public partial class VideoComponent : IIsContentPage { public bool IsContentPage { get; set; } } #endregion

    public interface ISectionSettings
    {
        string ItemsPerRow { get; set; }
    }
    
    public interface ISideNav
    {
        List<(string url, string name)> SideNav();
    }
    
    public class SiteConfig
    {
        public AppConfig AppConfig { get; set; }
        public Home Home { get; set; }
        public Nav Nav { get; set; }
        public Footer Footer { get; set; }
        public Alert Alert { get; set; }
        public Theme Theme { get; set; }
    }
    
    public partial class Article : ISectionSettings, ISideNav
    {
        public string ItemsPerRow { get; set; }
        public AppConfig AppConfig { get; set; }
        public List<(string url, string name)> SideNav()
        {
            var sideNav = new List<(string url, string name)>();
    
            foreach (var content in ContentBlocks)
            {
                switch (content.Content.ContentType.Alias)
                {
                    case TitleItem.ModelTypeAlias:
                        if (content.Content is TitleItem titleComponent)
                        {
                            sideNav.Add((titleComponent.Title.ToUrlSegment(), titleComponent.Title));
                        }
    
                        break;
    
                    case Markdown.ModelTypeAlias:
                        var markDown = content.Content as Markdown;
                        var htmlDoc = new HtmlAgilityPack.HtmlDocument();
                        if (markDown != null) htmlDoc.LoadHtml(markDown.Content.ToString());
                        var h2S = htmlDoc.DocumentNode.Descendants("h2");
                        sideNav.AddRange(h2S.Select(h2 => (h2.InnerText.ToUrlSegment(), h2.InnerText)));
                        break;
                }
            };
    
            return sideNav;
        }
    
            public Article Prev()
        {
            var prev = Siblings().SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
            return prev;
        }
    
            public Article Next()
        {
            var siblingsReversed = Siblings().OrderBy(y => y.DisplayDate).ToList();
            return siblingsReversed.SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
        }
    
            public List<Article> RelatedArticles(int take)
        {
            return Siblings().Where(x => x.Id != Id).OrderBy(arg => Guid.NewGuid()).Take(take).ToList();
        }
    
            private IEnumerable<Article> Siblings()
        {
            return this.SiblingsAndSelf().Select(x => new Article(x)).OrderByDescending(y => y.DisplayDate).ToList();
        }
    
        }
    
    public partial class Blogpost : ISectionSettings, ISideNav
    {
        public string ItemsPerRow { get; set; }
        public AppConfig AppConfig { get; set; }
        public List<(string url, string name)> SideNav()
        {
            var sideNav = new List<(string url, string name)>();
    
            foreach (var content in ContentBlocks)
            {
                switch (content.Content.ContentType.Alias)
                {
                    case TitleItem.ModelTypeAlias:
                        if (content.Content is TitleItem titleComponent)
                        {
                            sideNav.Add((titleComponent.Title.ToUrlSegment(), titleComponent.Title));
                        }
    
                        break;
    
                    case Markdown.ModelTypeAlias:
                        var markDown = content.Content as Markdown;
                        var htmlDoc = new HtmlAgilityPack.HtmlDocument();
                        if (markDown != null) htmlDoc.LoadHtml(markDown.Content.ToString());
                        var h2S = htmlDoc.DocumentNode.Descendants("h2");
                        sideNav.AddRange(h2S.Select(h2 => (h2.InnerText.ToUrlSegment(), h2.InnerText)));
                        break;
                }
            };
    
            return sideNav;
        }
    
        public Blogpost Prev()
        {
            var prev = Siblings().SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
            return prev;
        }
    
        public Blogpost Next()
        {
            var siblingsReversed = Siblings().OrderBy(y => y.DisplayDate).ToList();
            return siblingsReversed.SkipWhile(item => item.Id != Id).Skip(1).FirstOrDefault();
        }
    
        public List<Blogpost> RelatedArticles(int take)
        {
            return Siblings().Where(x => x.Id != Id).OrderBy(arg => Guid.NewGuid()).Take(take).ToList();
        }
    
        private IEnumerable<Blogpost> Siblings()
        {
            return this.SiblingsAndSelf().Select(x => new Blogpost(x)).OrderByDescending(y => y.DisplayDate).ToList();
        }
    
    }
    
    public class IconComposition
    {
        public string BorderColor { get; set; }
        public string IconColor { get; set; }
        public string FillGradient { get; set; }
    }
    
    public partial class PodsListSettings
    {
        public bool IsArticlePage { get; set; }
    }
    
    public partial class MiniIcon
    {
        public string IconColor { get; set; }
    
    }
    
    public partial class Nav
    {
        public bool AlternateNavBg { get; set; }
        public string ModelAlias { get; set; }
    }
    
    public partial class Person : ISectionSettings
    {
        public string ItemsPerRow { get; set; }
    }
    
    public partial class PodItem
    {
        public string BorderColor { get; set; }
        public string IconColor { get; set; }
        public string FillGradient { get; set; }
    }
    
    public partial class Product : ISectionSettings
    {
        public string ItemsPerRow { get; set; }
    
        public List<Product> RelatedProducts(int take)
        {
            return Siblings().Where(x => x.Id != Id).OrderBy(arg => Guid.NewGuid()).Take(take).ToList();
        }
        private IEnumerable<Product> Siblings()
        {
            return this.SiblingsAndSelf().Select(x => new Product(x)).ToList();
        }
    }
    
    public class ShareLinkSettings
    {
        public string Title { get; set; }
        public string TextClass { get; set; }
        public bool NoColumn { get; set; }
        public bool HasLargeIcons { get; set; }
        public string Alignment { get; set; }
        public bool IsCentered { get; set; }
    }
    
    public partial class ContactInformation
    {
        public string LinkClass { get; set;}
    }
    

    }

    You can see the public partial class Blogpost additions I made. This may be purely a models thing since I have to have my Blogpost.generated.cs Model file included in the project for that Model to be recognized. Im using ModelsMode=AppData in the web.config but I have also tried ModelsMode=LiveAppData. Having a bear of a time with Models in general. I am working with a Nuget pkg Install of the base Umbraco 8.10.1 site. Maybe thats the issue??

  • Robert Freeland 18 posts 90 karma points
    Feb 17, 2021 @ 18:56
    Robert Freeland
    0

    Here is the error:

    enter image description here

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 17, 2021 @ 19:23
    Matt Barlow | jacker.io
    2

    Okay.

    You don't need to include the Models folder or any of the class files within it, it should always be excluded from the project. The only reason to include them is to help with writing your extensions.

    So, exclude all the models files and make sure the project builds. Revert any changes you made to the _Amplify.cs file.

    Now, make your changes to your doc types via the backoffice, I guess you have added BlogPost. So there probaly isnt anything to do there.

    Now make sure the modelsbuilder mode is Dll, (you should have installed, the modelsbuilder and models builder UI nuget pacakges).

    Then in the back office you click build models. This regenerates all of the generated models class files, and compiles them into the Umbraco.Web.Published models dll. So we now have the model built for blogpost. (but it's not extended yet)

    Now we will add the changes you want to the models. So temporarily add the models folder to your solution (this will give you intellisense). Now make the changes to blogpost you require in the _amplify.cs file.

    Save everything, now remove the models folder, we don't want this getting built (basically it acts as a blueprint for the compiled dll). The actual compilation is taken care of by running the models builder via the backoffice.

    Now, go into the backoffice and build your models again. This should now pick up the extended changes and compile them into the Umbraco.Web.Published .dll.

    Build your solution, now everything should work.

  • Robert Freeland 18 posts 90 karma points
    Feb 17, 2021 @ 21:22
    Robert Freeland
    1

    Matt.....BRILLIANT!!! I guess the ModelBuilders was the whole issue I had all along. Nobody has taken the time to explain in detail how to get the models all synced up. Really appreciate you taking your time to explain. You Rock!!

  • Matt Barlow | jacker.io 164 posts 727 karma points c-trib
    Feb 17, 2021 @ 22:02
    Matt Barlow | jacker.io
    0

    No worries, glad you got it working. Yeah, the whole models builder thing is a little complicated.

    It's designed to give flexibility but I think it's just really confusing having all these different modes.

  • Robert Freeland 18 posts 90 karma points
    Feb 17, 2021 @ 22:11
    Robert Freeland
    0

    Again, The help is GREATLY appreciated. Now if I can figure out how to wire the Members up to AD I will be nearly home free!! Thanks again....

Please Sign in or register to post replies

Write your reply to:

Draft