Copied to clipboard

Flag this post as spam?

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


  • Vaughan 3 posts 83 karma points
    Dec 18, 2020 @ 10:03
    Vaughan
    0

    New to Umbraco - application errors trying to create new templates/pages

    Help!

    I have been thrown in the deep end to build a new section into an existing live site built on Umbraco 7.10.x.

    I have been going through the documentation and video tutorials on Umbraco.tv and have been able to grok most of the methodology and process.

    It seems pretty straightforward, however, when trying to implement what I have learned I have hit a roadblock and when creating the document types, templates and content - when previewing or publishing, I get an application error.

    At this point, I have no idea how to solve this, or if this is a server side issue out of my control.

    Briefly, I am trying to build out a section for newsletters - that is, one page which will list all the newsletters, and then a series of newsletters, each comprised of several articles.

    Application error as follows:


    Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0234: The type or namespace name 'Newsletter' does not exist in the namespace 'MDSLegal.Web.Umbraco.Models' (are you missing an assembly reference?)

    Source Error:

    Line 40:
    Line 41:
    Line 42: public class PageViewsNewsletterscshtml : Umbraco.Web.Mvc.UmbracoTemplatePage

    Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\f7da5c7c\52a28129\AppWebnewsletters.cshtml.65a2d1ee.pwe_q1q9.0.cs Line: 42


    I'm really hoping there is someone out there who can assist a total Umbraco n00b to understand why I'm getting an app error, help me solve it and to get back to developing what I need to.

    If anyone is happy to assist over Skype of FB messenger, that would be awesome.

    I really like the potential Umbraco offers, but hitting this roadblock this early is very frustrating, especially since I've followed the tutorials and am not getting the same results.

    Thank you for taking the time to read my post. :[

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Dec 19, 2020 @ 09:54
    Marc Goodson
    0

    Hi Vaughan

    The deep end hey? well, the water is lovely, once you get used to it...

    There are several approaches to building Umbraco sites, and so it will depend a little on the way your existing site has been built, and whether you are working locally with Visual Studio, or directly on a live site via the /umbraco backoffice Url.

    Essentially your error is related to 'Models'.

    You can run an Umbraco site with something called Modelsbuilder turned on or turned off.

    https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/index-v7

    In the developer section of Umbraco there should be a Modelsbuilder tab, and this should tell you whether Modelsbuilder is on and off, and which mode it is running in.

    When Modelsbuilder is turned on, every Document Type you create has a generated 'Model' with matching name, into a common namespace - and properties of the Doc Type have generated matching properties on the model.

    This means at the top of your views/templates you'll have a @using statement that tells the view what type of Model it related to eg

    @inherits UmbracoTemplatePage<MyLovelyDocumentTypeModel>
    

    and you'd be able to write out properties from the content item based on the document type like so:

    <h1>@Model.Content.PageTitle</h1>
    

    If you don't have Modelsbuilder turned on, you would have a more generic inherit statement eg:

    @inherits UmbracoTemplatePage
    

    and

    <h1>@(Model.Content.GetPropertyValue<string>("pageTitle"))</h1>
    

    So with Modelsbuilder turned off, you don't have to worry about specifying the correct Model, but the downside is you have to remember and type the alias of the properties correctly...

    ... with Modelsbuilder turned on - magic though it seems, there is another step - when you change a Document Type or Property, you need to trigger the 'regeneration' of the models.

    And this is where it gets (more) confusing...

    The Modelsbuilder can be setup to run in different modes to suit your development workflow.

    The default is 'PureLive' and in this mode the Models are generated into Memory and should be updated just a soon as you make a change to a Document Type. (it is like magic)

    If however you are working with Visual Studio, it's really nice to have intellisense on the models, and also if you want to extend them, and Visual Studio won't know about the models if they are generated into memory.

    So there is a setting called AppData, if Modelsbuilder is running in this mode, it will generate the models into the AppData folder of your solution, and to use them in Visual Studio, the files will need to be included into your Solution, and the project will need to be recompiled for Umbraco to be able to use them in the views.

    But in more complex scenarios you might want the models generated as a dll to share across other projects, or have them generated in a different project, so there are also two other modes: dll and api...

    The gist of this whole thing is that you have created a Newsletter document type, and the View/Template is presumably inheriting from what the generated model would be:

    @using MDSLegal.Web.Umbraco.Models
    @inherits UmbracoTemplatePlage<Newsletter>
    

    but the View/Template is throwing an error to say that this Type doesn't exist in the namespace: MDSLegal.Web.Umbraco.Models

    So this means that your models need to be regenerated.

    If you visit the developer section, and find the Modelsbuilder tab and dashboard, there should be a button here to regenerate the models - which may fix your problem instantly... but it will also tell you which mode Modelsbuilder is running in, and if it's set to AppData or Api, then, you'll need to recompile the project in Visual Studio in order to be able to use the model in the view...

    Anyway hopefully that gives you some insight into what is going on, hopefully it's just a case of pressing the regeneration button to get you going again.

    regards

    Marc

  • Vaughan 3 posts 83 karma points
    Dec 20, 2020 @ 06:58
    Vaughan
    0

    Marc, thank you so much for your reply. Unfortunately, most of it is over my head and I fear that there is a missing third-party involved.

    I find it very strange that the client did not go back to their original developer to add this newsletter functionality that they now want. I've been liaising with them on and off for over 6 months now, it's been like pulling teeth.

    I've had a look at Developer / Models Builder and I don't see any option to "Regenerate models". Only this:

    Models Builder

    ModelsBuilder is enabled, with the following configuration:

    • The models factory is enabled.
    • The API is installed and enabled.
    • However, the API runs only with debug compilation mode.
    • External tools such as Visual Studio cannot use the API.
    • No models mode is specified: models will not be generated.
    • Models namespace is MDSLegal.Web.Umbraco.Models.
    • Static mixin getters are enabled. The pattern for getters is "Get{0}".
    • Tracking of out-of-date models is not enabled.

    I have no experience with VisualStudio - I tend to specialise in front-end design these days, my dev days are long behind me now.

    I have been attempting to build on the live site through the Umbraco backend UI, so to hit this roadblock now is a real kick in the nuts.

    There have been so many red flags with this client, I am this close to refunding their deposit and washing my hands of the whole project - which is a pity, since I was excited to delve into Umbraco.

    I appreciate your help, thank you again.

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Dec 20, 2020 @ 08:01
    Marc Goodson
    100

    Hi Vaughan

    Hopefully this experienced doesn't dint your excitement for playing around with Umbraco - as this situation isn't a shining typical example of how you would normally work with Umbraco!

    The previous developers have hit upon a particular developer workflow that suited their process, but that is strangling a bit, how you might pick this up.

    From the information you provide from the Modelsbuilder tab, it shows the problem is the generation of these Models - and you don't have the regenerate button, because they have decided to use an approach (API mode) that requires the models to be generated and built/compiled in Visual Studio first and then deployed to the production site.

    There is more information on Modelsbuilder API mode in this article here: https://richardballard.co.uk/using-umbraco-models-builder-api-in-visual-studio/

    But that might not be an appealing direction for you to go in, and if you haven't the project setup in Visual Studio, is going to be a pain to setup!

    So your other option, other than refunding the deposit! - is to ignore Modelsbuilder syntax in your template.

    Because Modelsbuilder is turned 'on' when you create a new template, Umbraco will automatically stuff the following at the top of the View

    eg

    @inherits UmbracoTemplatePage<Newsletter>
    

    Change this to be

    @inherits UmbracoTemplatePage
    

    Blank out the rest of the template html and content - see if this works without throwing an error!

    Then you can write out properties using the IPublishedContent syntax

    eg

    <h1>@Model.Content.GetPropertyValue("pageTitle")</h1>
    

    There is some guidance for syntax here: https://our.umbraco.com/Documentation/Reference/Querying/IPublishedContent/index-v7

    This should allow you to build the templated view and html without getting the error you are experiencing, because you won't be trying to access the Modelsbuilder model.

    There may be 'other problems' if the View is inheriting a master view layout that is expecting a modelsbuilder model, but it will be interesting to see if you can at least write out a page with a <h1> without error!

    regards

    Marc

  • Vaughan 3 posts 83 karma points
    Dec 21, 2020 @ 12:36
    Vaughan
    0

    You absolute legend Marc!

    I've had some success getting the pages to render without error! And, I've been able to see mark-up added to the templates - and I've also been able to retrieve some property values from my Document Types - hallelujah! I just popped back here to say thank you, I might yet be able to get this job done - thank you!

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Dec 21, 2020 @ 16:53
    Marc Goodson
    0

    ahh, Vaughan that's great to hear!

    good luck with the rest of the job - sure people will help out on other issues here if you hit any other sticking points.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft