Copied to clipboard

Flag this post as spam?

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


  • Morten 105 posts 345 karma points
    Mar 09, 2017 @ 09:39
    Morten
    0

    BUG: } expected if inside first block @{}

    This is a weird issue, and I don't know if Umbraco is at fault or Razor. This is basically what I have:

    @{
        Layout = null;
        var home = @CurrentPage.Site();
    
        string url = "";
    
        if (true == true)
        {
            url = "test";
        } 
        else if (true == false)
        {
            url = "test";
        }
    }
    

    Obviously changed out my if-statements. This is valid (although it never gets past the first if-statement) and should work, but I get an:

    } expected

    when I try to run it. If I do this, however, it works fine:

    @{
        Layout = null;
        var home = @CurrentPage.Site();
    
        string url = "";
    }
    
    @{
        if (true == true)
        {
            url = "test";
        } 
        else if (true == false)
        {
            url = "test";
        }
    }
    

    Why do I need to make a completely new @{} code block to get rid of this error? Visual Studio just fails to format my code (but it's not invalid), yet I get the error when I try to display the page.

    Razor, Umbraco, or my mistake?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 09, 2017 @ 09:55
    Michaël Vanbrabandt
    100

    Hi Morten,

    you can also remove the @ from CurrentPage like:

    var home = CurrentPage.Site();
    

    /Michaël

  • Morten 105 posts 345 karma points
    Mar 09, 2017 @ 10:34
    Morten
    1

    God dammit, that seems to be the issue.

    Thanks a lot haha!

  • Morten 105 posts 345 karma points
    Mar 09, 2017 @ 10:41
    Morten
    0

    Damn, sorry for creating this inside the Vorto subforum. That was definitely not my intention!

Please Sign in or register to post replies

Write your reply to:

Draft