Copied to clipboard

Flag this post as spam?

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

  • Sarah Marriott 2 posts 82 karma points
    Dec 13, 2018 @ 16:48
    Sarah Marriott

    Noob Question - Partial View Macros


    I am just learning Umbraco, and have been following the tutorials. I have setup my own document types, but essentially replaced the word 'Article' for 'Lesson' for my own purposes.

    I am encountering an error when following this article

    This is specifically in the razor code for the Partial view Macro File

    The error is:

    'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'lessonContents'

    my code is:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{ var selection = Model.Content.Site().FirstChild("lessonsMain").Children("lesson") .Where(x => x.IsVisible()) .OrderBy("CreateDate desc"); }

    @foreach(var item in selection){
        <div class="article">
        <div class="articletitle"><a href="@item.Url">@item.Name</a></div>
        <div class="articlepreview">@Umbraco.Truncate(@item.lessonContents,100) <a href="@item.Url">Read More..</a></div>

    I have a property in my Lesson document type named accordingly: enter image description here

    Can anyone point out where i may be going wrong?



  • Alex Skrypnyk 5329 posts 19613 karma points MVP 3x admin c-trib
    Dec 14, 2018 @ 00:37
    Alex Skrypnyk

    Hi Sarah

    Welcome to our forum!!!

    enter image description here

    Try this code:

    <div class="articlepreview">@Umbraco.Truncate(@item.GetPropertyValue<string>("lessonContents"),100) <a href="@item.Url">Read More..</a></div>

    "item" is a PublishedContent class, you can't access property values just by property alias.

    You have to use strongly typed models and models builder, read more -

    Or just use as I showed you "item" and GetPropertyValue("propertyAlias") method. Read more about Umbraco helper methods -

    Post as many questions as you can and we will do great progress in Umbraco learning together with the community!



  • Sarah Marriott 2 posts 82 karma points
    Dec 14, 2018 @ 08:58
    Sarah Marriott

    Thank you Alex,

    I've just tried your code and it works perfectly!

    I'll read the documentation links you've given me - I am really keen to learn Umbraco as I think it could be a fantastic tool.

    Oh, and I will definitely be back here when I get stuck again ;-)

    Thanks again,


Please Sign in or register to post replies

Write your reply to: