jaffa
jaffa

Reputation: 27360

How do you use enum inside switch statement using MVC & razor view engine?

I have a service which returns a Json data structure. One of the properties in the data is an enum value. When the Json is returned inside the client, I'd like it to react to the data returned using a switch statement.

I don't want to hard-code the enum values in the javascript, so I tried using case @MyEnum.Value, but the view renders it simply as 'Value'. I need it to output the actual value of the enum for it to work.

How can I get this to work, or alternatively is there a better method for handling this situation?

Upvotes: 1

Views: 1779

Answers (1)

CD..
CD..

Reputation: 74166

Try @((int)MyEnum.Value) for getting the value

Upvotes: 3

Related Questions