Copied to clipboard

Flag this post as spam?

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


  • Martin Rud 232 posts 902 karma points c-trib
    Jan 01, 2020 @ 20:53
    Martin Rud
    0

    Rendering nested content with items with content picker property: Argument 1: cannot convert from method group to HelperResult

    Hi forum,

    In a template for my slideshow document type I want to render all the items added to a Nested content property:

    • In the slideshow document type I have a property called slides
    • slides property is a Umbraco.NestedContent datatype with one document type (nested_slides) in its configuration
    • nested_slides document type has two properties: slide (content picker data type) and foo (textstring - used just for testing/debugging)

    In my template I have this code:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using ContentModels = Umbraco.Web.PublishedModels;
    
    @{
        Layout = null;
    }
    @{
        var items = Model.Value<IEnumerable<IPublishedElement>>("slides");
        foreach(var item in items)
        {
            var slide = item.Value<IPublishedElement>("slide");
            var foo = item.Value<string>("foo");
    
            <p>slide: @slide.Id, foo: @foo</p>
        }
    }
    

    The code above is for proof of concept, but it gives an error in line 14:

    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: CS1503: Argument 1: cannot convert from 'method group' to 'HelperResult'
    
    Source Error:
    
    
    Line 12:        var foo = item.Value<string>("foo");
    Line 13:        
    Line 14:         <p>slide: @slide.Id, foo: @foo</p>
    Line 15:     }
    Line 16: }
    

    I want to get the id of the linked node so I can call Umbraco.Content to get the content of that linked node.

    What am I doing wrong?

  • Dunc 1 post 94 karma points
    Jun 30, 2020 @ 11:49
    Dunc
    103

    Hi,

    Just encapsulate it in brackets and it works.

    @(item.Value<string>("slide"))
    
Please Sign in or register to post replies

Write your reply to:

Draft