michal.jakubeczy
michal.jakubeczy

Reputation: 9479

Enum localization in web api

We have enum with following values:

But in web API we would like to accept their localized values instead of enum values (so 'Value 1' instead of Value1).

In client edmx property is generated as a string so the question is - will server accept 'Value 1' by default or do we have to implement special logic to handle it?

Upvotes: 0

Views: 708

Answers (1)

Ross Bush
Ross Bush

Reputation: 15185

If you are using localized resources then you can bind your resource entry to your enum using data annotations. For display, simply use the ResourceType property.

 [Display(ResourceType = typeof(RES.enums),Name = "enumSomeTypeValue1")]

In your service you will need to apply a transformation if you are converting the string representation of the enum or you will get an error if the string does not match the enum member name.

Perhaps you could create a method to resolve the localized label back to the associated enum.

Upvotes: 1

Related Questions