Implementing a switch statement in a CSHTML page

后端 未结 4 1306
谎友^
谎友^ 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:19

    This doesn't answer your question, as indicated by the question's title, but it does solve the problem you described in the body of the question.

    Use a view model class as the view's model and add a method that includes the switch statement. Then just call the method from the view via @Model.MethodWithSwitchStatement(). [The id can be saved in the view model object.]

提交回复
热议问题