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

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

Up vote 1 down vote favorite 1 share g+ share fb share tw.

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? Asp. Net-mvc-3 razor link|improve this question asked Aug 15 '11 at 8:53jaffa1,674827 85% accept rate.

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

Great thanks for the answer! – jaffa Aug 15 '11 at 16:23.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions