Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Aug 09, 2017 @ 14:17
    Claushingebjerg
    0

    Rendering nested content from another page

    Im trying to render nested content from a specific node on a different page. The code is a partial

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
      @{
            var source =  @Umbraco.Content(1056);
            var items = source.GetPropertyValue<IEnumerable<IPublishedContent>>("sponsorer");
    
     }
    
        <div>   
            @foreach(var item in items) {
                    <p>@item.Name</p>
            }
        </div> 
    

    I get the error "Parser Error Message: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup."

    if i remove "<IEnumerable<IPublishedContent>>" i can get the loop of nested content nodes, but can't render property values, only the name of each nested content node.

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Aug 09, 2017 @ 14:21
    Lee Kelleher
    0

    Hi Claus,

    Try swapping @Umbraco.Content with @Umbraco.TypedContent - as that will give you a strongly-typed object, rather than a dynamics one.

    Cheers,
    - Lee

  • Claushingebjerg 939 posts 2574 karma points
    Aug 09, 2017 @ 14:40
    Claushingebjerg
    0
    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        var source = @Umbraco.TypedContent(1056);
        var items = source.GetPropertyValue<IEnumerable<IPublishedContent>>("sponsorer");
    }
    
    <div>   
        @foreach(var item in items) {
            <p>@item.Name | </p>
        }
    </div>
    

    Still getting: "Parser Error Message: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup."

    If i remove <IEnumerable<IPublishedContent>> now i get an erro saying "Compiler Error Message: CS1579: foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'"

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Aug 09, 2017 @ 14:43
    Lee Kelleher
    0

    When you get the Parser Error Message error... does it give any line numbers?

    I can't spot anything immediately obvious from your code snippet.

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Aug 09, 2017 @ 15:05
    Nik
    0

    This sounds like a real cop out answer, but I've had this before and basically, it had gotten confused within the file. I resolved it by re-creating the partial view and typing the code out again.

  • Claushingebjerg 939 posts 2574 karma points
    Aug 09, 2017 @ 19:36
    Claushingebjerg
    0

    enter image description here

  • Claushingebjerg 939 posts 2574 karma points
    Aug 09, 2017 @ 19:51
    Claushingebjerg
    101

    Fixed it

    its was the "@" in @Umbraco.TypedContent(1056)... Should be Umbraco.TypedContent(1056)

  • 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