Copied to clipboard

Flag this post as spam?

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


  • Arly Berg 3 posts 73 karma points
    Oct 31, 2016 @ 10:52
    Arly Berg
    0

    Error CS1513: } in Umbraco generated file

    Hi

    I have the following code snippet

    @{
                        var nodes = umbraco.uQuery.GetNodesByName("Nyheder");
                        if (nodes.Any())
                        {
                            IPublishedContent node = Umbraco.TypedContent(nodes.First().Id);
                            var children = node.Children().Where("Visible");
                            var selection = children.OrderBy("CreateDate desc");
    
    
                            int counter = 0;
    
                            foreach (var item in selection)
                            {
                                DateTime startDate = DateTime.Parse(@item.GetPropertyValue("publishedFrom").ToString());
                                DateTime endDate = DateTime.Parse(@item.GetPropertyValue("publishedTo").ToString());
    
                                string author = @item.GetPropertyValue("CreatorName").ToString();
    
    
                                if ((startDate <= DateTime.Now) && (endDate > DateTime.Now))
                                {
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            @item.GetPropertyValue("NyhedOverskrift")
                                        </div>
    
                                        <div class="panel-body">
                                            @item.GetPropertyValue("nyhedsIndhold")
                                        </div>
                                    </div>
    
                                    counter++;
                                }
    
                                if (counter > 2)
                                {
                                    break;
                                }
    
                            }
                        }
                    }
    

    When I remove the line with "author" it works fine. When I add it, it breaks in the file genereated by Umbraco (\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\b57d6c43\a8a0a4ec\AppWebhomepage.cshtml.65a2d1ee.tz2gnzwb.0.cs) with an error CS1513: } was expected.

    I simply can't figure out what is wrong, but my guess is that is maybe has something to do with the nested divs or an error in Umbraco :-)

    Can anyone shed some light on this, please?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Oct 31, 2016 @ 11:43
    Dave Woestenborghs
    0

    Hi Arly,

    Can you change this line :

      string author = @item.GetPropertyValue("CreatorName").ToString();
    

    to this

      string author = item.GetPropertyValue("CreatorName").ToString();
    

    Dave

  • Casper 70 posts 308 karma points
    Oct 31, 2016 @ 11:48
    Casper
    0

    I may have todo with the "@" signs you use where not needed:

    DateTime startDate = DateTime.Parse(@item.GetPropertyValue("publishedFrom").ToString());`
    DateTime endDate = DateTime.Parse(@item.GetPropertyValue("publishedTo").ToString());
    

    Try removing them. If the error keep coming up, then try to delete the temporary file causing the error.

    @{ 
        var nodes = umbraco.uQuery.GetNodesByName("Nyheder"); 
        if (nodes.Any()) 
        { 
            IPublishedContent node = Umbraco.TypedContent(nodes.First().Id); 
            var children = node.Children().Where("Visible"); 
            var selection = children.OrderBy("CreateDate desc");
    
            int counter = 0;
    
            foreach (var item in selection)
            {
                DateTime startDate = DateTime.Parse(item.GetPropertyValue("publishedFrom").ToString());
                DateTime endDate = DateTime.Parse(item.GetPropertyValue("publishedTo").ToString());
    
                string author = item.GetPropertyValue("CreatorName").ToString();
    
    
                if ((startDate <= DateTime.Now) && (endDate > DateTime.Now))
                {
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            @item.GetPropertyValue("NyhedOverskrift")
                        </div>
    
                        <div class="panel-body">
                            @item.GetPropertyValue("nyhedsIndhold")
                        </div>
                    </div>
    
                    counter++;
                }
    
                if (counter > 2)
                {
                    break;
                }
    
            }
        }
    }
    
  • Arly Berg 3 posts 73 karma points
    Oct 31, 2016 @ 12:18
    Arly Berg
    0

    Hi

    Thanks for the advise, Dave - Made me understand was really was the problem :-)

    Removing the '@' signs made it come up with an "null reference" error. This made me realize that I did not have a property called 'CreatorName' but it actually was a build in property, so I didn't need the GetPropertyValue for this.

    Once corrected, evertyhings working :-)

    Thanks again

  • Arly Berg 3 posts 73 karma points
    Oct 31, 2016 @ 12:20
    Arly Berg
    0

    Hi

    Also thanks to you Casper - You both nailed it :-)

Please Sign in or register to post replies

Write your reply to:

Draft