Implementing a switch statement in a CSHTML page

后端 未结 4 1309
谎友^
谎友^ 2021-02-03 16:32

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:37

    @switch (id)
    {
        case "test": 

    Test Site

    break; case "prod":

    Prod Site

    break; }

    There is no need to enclose the entire switch statement in a @{} block, (unlike Joel Etherton's post)

    Your errors are basically regular syntax errors and have nothing to do with razor;

    1. the variable wasn't in parenthesis

    2. the body of switch wasn't in brackets

    3. no "break" after the first statement.

提交回复
热议问题