Copied to clipboard

Flag this post as spam?

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


  • Bojko Bojkov 1 post 72 karma points
    Feb 16, 2018 @ 12:03
    Bojko Bojkov
    1

    Intellisense using strongly typed models

    Hello guys, finally registered after searching for a few days without achieving any results. So .. fairly new with Umbraco (also fairly new to programming) and I'm having a problem with traversing child nodes of a document type and getting the "cannot bind source content type umbraco..." error. I want to use strongly typed content using "UmbracoViewPage" (using Dll Models Builder) But Bojko show us some code. Right away kind sir.

    So I have a document type "News Archive" which is having regular stuff: Title, Body Text. Not much. And a document type News Article, which is a child node of 'News archive'. what I want to do is list all 'news articles' in the news archive page, regular stuff. So i'm accessing the collection of articles "var articles = Model.Site().FirstChild("newsArchive").Children("newsArticle").Where(x => x.IsVisible());"

    and now I can foreach them @foreach (var article in articles)

    and now to the question, is there any way to use some intellisense article.articleTitle article.articleBodyText .. etc.. Right now I'm using @article.GetPropertyValue("alias"), but I'm not feeling happy about myself using magic strings. and if i type @inherits UmbracoViewPage

    p.s. cheers from Bulgaria. p.s2. if any - sorry for grammar and spelling errors.

  • Streety 358 posts 568 karma points
    Feb 16, 2018 @ 19:16
  • Damien Holley 179 posts 540 karma points
    May 06, 2019 @ 08:10
    Damien Holley
    1

    For others & in case you couldn't get any further:

    1. in web.config change PureLive to LiveDll, recompile.
    2. In the Umbraco backoffice go to the developer section, open the modelsbuilder tab and click the Generate Models button.
    3. Back in your project you should be able to use the models from the publishedcontent where UmbracoHelper is being used, but I prefer to reference the Umbraco.Web.PublishedContentModels.dll in the Bin folder of the project that way I can use them easily anywhere within the program without using all the Umbraco overhead if it is not needed.

    Now, if anyone reads this, do you know how to get an equivalent function to Umbraco.TypedContentAtRoot() ?

Please Sign in or register to post replies

Write your reply to:

Draft