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 84 karma points
    Jan 08, 2019 @ 19:57
    Sarah Marriott
    0

    Displaying Nested content

    Hi,

    I am new to Umbraco and just building my first website using v7.12.4

    I have become stuck trying to display nested content in my template. I have tried following the documentation here:https://our.umbraco.com/Documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content

    However I am getting the following error:

    Compiler Error Message: CS1928: 'Umbraco.Web.Models.PartialViewMacroModel' does not contain a definition for 'GetPropertyValue' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.GetPropertyValue<T>(Umbraco.Core.Models.IPublishedContent, string)' has some invalid arguments
    

    Error

    Please see below an image of my document type

    Nested Content

    I have placed my code in a Partial View Macro File (I hope this is right) and can be seen here:

    @using Umbraco.Web
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("ideaLinks");
    
        foreach(var item in items)
        {
            <h3>@item.GetPropertyValue("title")</h3>
            @Umbraco.Field(item, "method")
        }
    }
    

    Can anyone see where I may be going wrong?

    I have scoured the net for a solution, but to no avail - it must be something simple!

    Thanks!

    Sarah

  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Jan 08, 2019 @ 20:58
    Søren Kottal
    100

    Hi Sarah

    You don't have to place your code in a Partial View Macro File. You can put it in your document types template instead, or if you prefer a partial, a Partial View.

    You need to inherit from UmbracoViewPage, to have the IPublishedContent in Model.

    Also, I would advise against using @Umbraco.Field() for getting properties. Use Model.GetPropertyValue(), or ModelsBuilder.

  • Sarah Marriott 2 posts 84 karma points
    Jan 08, 2019 @ 21:13
    Sarah Marriott
    2

    Hey Søren,

    Thanks so much for the quick reply - I've put the code in a Partial View (i didn't know about those!) and added the inherits and it works!

    Thanks again!

    This forum is invaluable :)

    Sarah

  • 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