Implementing a switch statement in a CSHTML page

后端 未结 4 996
一整个雨季
一整个雨季 2021-02-03 16:50

I\'m trying to do something different. I have a view that contains an Id. Based on the value of the Id I want to change my heading that appears. Something like:

         


        
4条回答
  •  余生分开走
    2021-02-03 17:29

    Your switch needs to be completely enclosed in a block and it needs to be "broken" properly:

    // Use the @{ } block and put all of your code in it
    @{
        switch(id)
        {
            case "test":
                // Use the text block below to separate html elements from code
                
                    

    Test Site

    break; // Always break each case case "prod":

    Prod Site

    break; default:

    WTF Site

    break; } }

    Because the

    tags are enclosed html blocks by themselves, you may not need the blocks for separation. It's just my habit to include them.

提交回复
热议问题