Hello,
I'm using Umbraco 6.0.4
I tried to use one if the code samples from the Umbraco website (which I downloaded from Umbraco website) to a Macro Script (Developers - Scripting Files) but always got the following error:
"cs(433): error CS1513: } expected"
And this is the code I use - just copy-paste - didn't change nothing - I took it from here:
http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/razor-recipes/news.aspx
@{ var pagesToList = @Model.Children.Where("Visible"); //Check macro param is not empty, if so default to 6 otherwise use the Parameter value var itemsPerPage = String.IsNullOrEmpty(Parameter.noPerPage) ? 6 : int.Parse(Parameter.noPerPage); //Count number of items from pagesToList variable var numberOfItems = pagesToList.Count(); //Set the currentPage to 1 int currentPage = 1; /* If we cannot parse a number from requesting the querystring param 'page' then set to 1, otherwise set the querystring value to our currentPage variable */ if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) { //No querystring found or not a number, so set currentPage to 1 currentPage = 1; } //Subtract one from the currentPage variable (to use a zero based index, first page = 0) currentPage--; //Number of Pages (Maths time!) /* Divide the numberOfItems by itemsPerPage and then round the number up to next whole number and add one to the result (eg: 5.1 = 6 + 1 = 7) */ var numberOfPages = Math.Ceiling((decimal)numberOfItems / (decimal)itemsPerPage); //Display the items in groups of 3 wrapped with a <div> <div id="gridText"> @* For each newsItem from our source (pagesToList) Where the page querystring = 2 /currentPage = 1... Skip over 6 records (currentPage * itemsPerPage) eg: 1*6 = 6 Take 6 records, which grabs 7,8,9,10,11 & 12 *@ @foreach (var itemGroup in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage) .InGroupsOf(3)) { <div class="group"> @foreach (var newsItem in itemGroup) { var newsCopy = newsItem.BodyText; newsCopy = Library.StripHtml(newsCopy); newsCopy = Library.Truncate(newsCopy, 50, true); <article class="item"> <h3><a href="@newsItem.Url">@newsItem.Name</a></h3> <p>@newsCopy</p> </article> } </div> } </div> <ul id="paging" class="group"> @{ /* pageQuerystring = 1 == 0 = currentPage pageQuerystring = 2 == 1 = currentPage */ //PREVIOUS Link <li> @if (currentPage > 0) { <a href="?page=@(currentPage)">« Previous</a> } else { <span class="pagingDisabled">« Previous</span> } </li> //Create a variable 'pages' that stores from 1 to the numberOfPages variable var pages = Enumerable.Range(1, (int)numberOfPages); //Loop through the numbers in the Pages variable foreach (var number in pages) { <li> @if (number - 1 != currentPage) { <a href="?page=@number">@number</a> } else { <span>@number</span> } </li> } //NEXT Link <li> @if (currentPage < pages.Count() - 1) { <a href="?page=@(currentPage + 2)">Next »</a> } else { <span class="pagingDisabled">Next »</span> } </li> } </ul> }
Now, the line that cause the error is this:
if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) { //No querystring found or not a number, so set currentPage to 1 currentPage = 1; }
The wired thing is that if for example I put it into <span> </span> there isn't error...
I can live without the "If" statement but the point is that I want to add also switch statment to this code (in order to handle each category) - but I can't do it with this error - did anyone had also this error?
How do I solve it? I tried to add as many "}" as possible but it's not accept it - the error just keep show.
Thanks