Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Mar 26, 2013 @ 22:15
    Amir Khan
    0

    Razor error depending for curly brace

    I'm getting this error depending on where I move an <a> markup, does anyone know why this would happen?

    No error:

    @helper renderModal()
    {
    var linkMode = @Model.videoOrImageLink.Mode;
    var linkUrl = @Model.videoOrImageLink.Url;
    string linkModeString = linkMode.ToString();
    <a href="@linkUrl" rel="prettyPhoto" class="triggerOverlay">View Larger</a>
    if(@linkModeString == "Media")
    {

    }
    }

    Error:

    @helper renderModal()
    {
    var linkMode = @Model.videoOrImageLink.Mode;
    var linkUrl = @Model.videoOrImageLink.Url;
    string linkModeString = linkMode.ToString();

    if(@linkModeString == "Media")
    {
    <a href="@linkUrl" rel="prettyPhoto" class="triggerOverlay">View Larger</a>
    }
    }

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2013 @ 23:13
    Jan Skovgaard
    0

    Hi Amir

    What error do you get? And what version of Umbraco are you using? It may be a bug that's the cause since there have been some issues in Umbraco 6 razor implementation I think.

    Looking forward to hearing from you.

    /Jan

  • Amir Khan 1282 posts 2739 karma points
    Mar 26, 2013 @ 23:18
    Amir Khan
    0

    Hi Jan, it is version 6.0, I was able to fix it by dropping the "@" before Model. It seems odd that it would fail with "error CS1513: } expected".

    Here's the updated code that works:

    @helper renderModal()
    {
    var linkMode = Model.videoOrImageLink.Mode;
    var linkUrl = Model.videoOrImageLink.Url;
    string linkModeString = linkMode.ToString();

    if (@linkUrl == "")
    {

    }

    else if(@linkModeString == "Media")
    {
    <a href="@linkUrl" rel="prettyPhoto" class="triggerOverlay">View Larger</a>
    }
    else if (@linkModeString == "URL"){
    <a href="@linkUrl" rel="prettyPhoto" class="triggerOverlay">Play Video</a>
    }
    }
    }

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2013 @ 23:33
    Jan Skovgaard
    0

    Hi Amir

    Ok, are you then using MVC or still webforms? There is a difference in the Razor implementation wether you're using the one or the other. However I think it would be weird if the syntax elements would differ...so it could perhaps also be a minor bug that's the cause. I know there have been some bugs with the implementation unfortunately.

    /Jan

  • Amir Khan 1282 posts 2739 karma points
    Mar 26, 2013 @ 23:43
    Amir Khan
    0

    Hi Jan, using webforms.

    Seems to me like consistency should be the key as I suspect people will be jumping between project that use each.

    -Amir

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2013 @ 23:45
    Jan Skovgaard
    0

    Hi amir

    I'm sure it's as consistent as it can be - and the core concepts are the same. But the mvc implementation differs as there are more things that can be done as far as I know. (I'm still a bit of a Razor n00b - xslt is still more my thing) :)

    /Jan

  • Amir Khan 1282 posts 2739 karma points
    Mar 26, 2013 @ 23:49
    Amir Khan
    0

    Yeah, makes sense. Just lots of changes going on, there's bound to be some roadbumps on the way.

  • gary 385 posts 916 karma points
    Mar 27, 2013 @ 01:05
    gary
    0

    Hi Amir

    V6 does use Razor V2 for both webforms and MVC, there have been some syntax changes, not many, but enough to stop some code that worked in say 4.7 from working in newer versions.

    One change is, in a code block @{} you should not need additional @, this breaks the block, hence you need to close it, therefore your error of expected } is correct.

    If you check with Visual Studio, as all of your code is in a block, the var when called     if (@linkUrl == "") , you should be able to remove this @, too.

    Have been searching for some documentation on razor V2, but without anything that really explains what is relevant to us here in Umbraco. 

    For the record, I now don't enter the @ until Visual Studio says it doesn't like it without, especially as the @ is Ctrl+alt+2 on my keyboard and curly braces Ctrl+alt+7 and Ctrl+alt+0, if I can enter them once each, its all good.

    Hope it helps a bit, sorry cannot be more precise

    regards G

Please Sign in or register to post replies

Write your reply to:

Draft