Copied to clipboard

Flag this post as spam?

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


  • Lorenzo Mercati 22 posts 45 karma points
    Jul 24, 2014 @ 10:05
    Lorenzo Mercati
    0

    angular var inside razor

    Good morning, I have this problem, if I do:

     @{    var pippo = "{{status.utente}}";   }

               <p>utente:  @pippo </p>

    I retreve the utente number correctly but if I do:

     @{

                    var pippo = "{{status.utente}}";

                    int gigi = int.Parse(pippo);

                    var nome = Umbraco.Member(gigi).Name;

                }

               <p>utente:  @nome </p>

    during parsing I retreve an error "Input string was not in a correct format."

    May you help me?

    Thanks in advance.
    Lorenzo

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jul 24, 2014 @ 13:49
    Andy Butland
    0

    You seem to be mixing up client side and server side code.  The variable "pippo" is getting defined as the literal string "{{status.utente}}" which isn't going to parse as an integer.  Hard to help further without seeing what you are trying to do, but looks like you need to rethink things here.

    Anything within @{ } in Razor is C# code, evaluated server side.

    For client side code it should be within a <script></script> block.

    Andy

  • Lorenzo Mercati 22 posts 45 karma points
    Jul 24, 2014 @ 15:30
    Lorenzo Mercati
    0

    Ok sorry, I try to explain,

    this code:  @{    var user = "{{status.user}}";   }

               <p>user:  @user </p>

    retrive the Id user (ex 1175), and it's ok I have user: 1175,

    but I want after use 1175 to umbraco helper to get user property but I can't convert to int.

    so when I do:

     @{

                    var user = "{{status.user}}";

                    int gigi = int.Parse(user);

                    var name = Umbraco.Member(gigi).Name;

                }

     

     

               <p>utente:  @name </p>

    it doesn't work.
    Any suggestion? 
Please Sign in or register to post replies

Write your reply to:

Draft