Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Oct 11, 2013 @ 12:07
    Kate
    0

    Simpel variabel problems

    Hi

    Im trying to print a variable, but I get the error:

    error CS0103: The name 'hey' does not exist in the current context

    @if(Model.NodeTypeAlias=="Produktion"){
          var hey = "Hey Production";
      }else if(Model.NodeTypeAlias=="Logistik"){
          var hey = "Hey log";                                           
      }else{
    var hey = "Hey you";  
    }
    <p>@hey</p>

    What am I dooing wrong?

    /Kate

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 11, 2013 @ 12:11
    Jeavon Leopold
    101

    Hi Kate,

    You just need to declare your variable before your if

    @{
        var hey = string.Empty;
    }
    @if(Model.NodeTypeAlias=="Produktion"){
           hey = "Hey Production";
      }else if(Model.NodeTypeAlias=="Logistik"){
           hey = "Hey log";                                            
      }else{ 
           hey = "Hey you";   
    }
    <p>@hey</p>
    

    Jeavon

  • Ben Norman 167 posts 276 karma points
    Oct 11, 2013 @ 12:15
    Ben Norman
    1
    @{
    var hey = "";
    }
    
    @if(Model.NodeTypeAlias=="Produktion"){
          hey = "Hey Production";
      }else if(Model.NodeTypeAlias=="Logistik"){
          hey = "Hey log";                                            
      }else{ 
          hey = "Hey you";   
    }
    
    <p>@hey</p>
    

    declare hey before the if statement so it is still in scope after the if statement

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 11, 2013 @ 12:19
    Fuji Kusaka
    0

    Hey Kate,

     string hey = "Hey production";
        if(CurrentModel.NodeTypeAlias=="Producktion"){       
           @hey
        }
        Or

        if(Model.Where("NodeTypeAlias == \"Producktion\"")){
            @hey
        }
  • Kate 267 posts 610 karma points
    Oct 11, 2013 @ 12:19
    Kate
    2

    Great, Thanks

    I tried it, but I just wrote:

    @{
       
    var hey = "";
    }

    Now I know how to do it.

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft