Copied to clipboard

Flag this post as spam?

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


  • hrg 32 posts 152 karma points
    Feb 06, 2017 @ 06:25
    hrg
    0

    : } expected umbraco razor

    I have following code block in my Partial view. It gives error : } expected. But I don't understand what is the issue as {} pairs matches.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{  
    var langstr = "All";
    var pageSize = 6;
    var max_pages=0;
    try
    {
        if (@ViewData["storylang"] == null)
        {
            langstr = "";
        }
        else
        {
            langstr = @ViewData["storylang"].ToString();
        }
    }
    catch (Exception ex)
    {
        langstr = "";
    }
    
    var pageIndex = (int)@ViewData["page_index"]; 
    dynamic selected;
    
    if (@ViewData["curpage"] != null){
    
        var id = (int)@ViewData["curpage"];
        var currentNode = Umbraco.TypedContent(id);
        selected = currentNode.Children.Where("Visible");
    
    
       if(langstr != ""){
            selected = currentNode.Children.Where("Visible").Where("language=\"" + @langstr + "\"");
            max_pages = currentNode.Children.Count();
            <ul>
                @foreach (var story in selected.Take(pageIndex * pageSize))
                {
    
                    <li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="story.Url" class="st-text">story.Name</a></li>
                }
            </ul>
    
        }
    
    }
    else
    {
        selected = CurrentPage.Children.Where("Visible");
        max_pages = CurrentPage.Children.Count();
        if(selected.Any()){
            <ul>
                @foreach (var story in selected.Take(pageIndex * pageSize))
                {
                    <li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="story.Url" class="st-text">story.Name</a></li>
                }
            </ul>
    
        }
      }
    }   
    

    can anyone debug the same?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Feb 06, 2017 @ 07:07
    Dave Woestenborghs
    100

    Hi hrg,

    I think there a issue with your syntax. You mixing code blocks and "rendering" blocks

    Can you try this :

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{  
        var langstr = "All";
        var pageSize = 6;
        var max_pages=0;
        try
        {
            if (ViewData["storylang"] == null)
            {
                langstr = "";
            }
            else
            {
                langstr = ViewData["storylang"].ToString();
            }
        }
        catch (Exception ex)
        {
            langstr = "";
        }
    
        var pageIndex = (int)@ViewData["page_index"]; 
        dynamic selected;
    }
    
    @if (ViewData["curpage"] != null){
    
        var id = (int)ViewData["curpage"];
        var currentNode = Umbraco.TypedContent(id);
        selected = currentNode.Children.Where("Visible");
    
    
       if(langstr != ""){
            selected = currentNode.Children.Where("Visible").Where("language=\"" + @langstr + "\"");
            max_pages = currentNode.Children.Count();
            <ul>
                @foreach (var story in selected.Take(pageIndex * pageSize))
                {
    
                    <li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story.Url" class="st-text">@story.Name</a></li>
                }
            </ul>
    
        }
    
    }
    else
    {
        selected = CurrentPage.Children.Where("Visible");
        max_pages = CurrentPage.Children.Count();
        if(selected.Any()){
            <ul>
                @foreach (var story in selected.Take(pageIndex * pageSize))
                {
                    <li class="col-lg-3 col-md-3 col-sm-6 col-xs-12"><a href="@story.Url" class="st-text">@story.Name</a></li>
                }
            </ul>
    
        }
      }
    

    Dave

  • hrg 32 posts 152 karma points
    Feb 06, 2017 @ 09:26
    hrg
    0

    Thanks ... it solved the issue. I got it.

Please Sign in or register to post replies

Write your reply to:

Draft