Copied to clipboard

Flag this post as spam?

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


  • Tim C 161 posts 528 karma points
    May 19, 2016 @ 09:42
    Tim C
    0

    Problem with matching { and }

    I am using a partial view to list the top 5 children of a specific node.

    This works, but only if I put a div before the

    foreach
    

    eg

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <div class="title">Test</div>
    
        <ul>
        @{
    
        var ow = @owCore.Initialise(1085); 
        <div> </div>
        var node = Umbraco.Content(1105);
    
    
        foreach (var item in node
                    .Children.Where("Visible")
                    .OrderBy("Id descending")
                 .Take(5)
                )
        {
    
            <li><a href="@item.Url">@item.pageTitle</a></li>
        }
    
    
    
    }   
    </ul>
    

    produces the expected unsorted list.

    However, if I remove the empty div

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <div class="title">Test</div>
    
        <ul>
        @{
    
            var ow = @owCore.Initialise(1085); 
    
            var node = Umbraco.Content(1105);
    
    
            foreach (var item in node
                        .Children.Where("Visible")
                        .OrderBy("Id descending")
                     .Take(5)
                    )
            {
    
                <li><a href="@item.Url">@item.pageTitle</a></li>
            }
    
        }   
    </ul>
    

    The error I get is

    Compiler Error Message: CS1513: } expected

    Source Error:

    Line 113: } Line 114: } Line 115:}

    Clear looks like too few closing '}'

    Presumably the div forces the closing }?

    I have checked owCore (it's a library of functions I am building in App_Code : however, I have stripped this back and it's now doing nothing just to make sure there are matched curly brackets:

    @using Umbraco
    @using Umbraco.Core.Models
    @using Umbraco.Web
    
    @functions{
    
    
    
        public static int Initialise(int siteDocID){
    
                return 0; 
        }
    
    }   
    

    However, if I remove the @owCore code from the partial view

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <div class="title">Test</div>
    
        <ul>
        @{
    
    
    
            var node = Umbraco.Content(1105);
    
    
            foreach (var item in node
                        .Children.Where("Visible")
                        .OrderBy("Id descending")
                     .Take(5)
                    )
            {
    
                <li><a href="@item.Url">@item.pageTitle</a></li>
            }
    
        }   
    </ul>
    

    All is ok again.

    Does that mean it's definitely an issue with the owCore or simply something else tripping the issue with mismatched {}

    I have checked the template calling this partial view and can't find a problem.

    This doesn't make sense. Can anyone explain?

    Thanks!

  • Tim C 161 posts 528 karma points
    May 19, 2016 @ 14:13
    Tim C
    1

    Solved thanks to reply to another post.

    don't need the @ in @owCore as this causes a new block to start!

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    May 19, 2016 @ 14:15
    Dennis Adolfi
    100

    Awesome Tim. I´ll post the Url to the other thread, in case someone has the same issue in the future and wants to find the solution quicker:

    https://our.umbraco.org/forum/templates-partial-views-and-macros/77396-syntax-of

  • 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