Tsarl
Tsarl

Reputation: 277

Converting boolean values to text in mvc

I was wondering what is the best way to convert a boolean value retrieved from the database to text for use in a display-field or textbox (e.g. true or false to Male or Female). Any suggestions?

Upvotes: 0

Views: 328

Answers (2)

daniele
daniele

Reputation: 177

@((bool)item.BooleanColumn ? "Yes" : "No")

Upvotes: 0

Random Dev
Random Dev

Reputation: 52280

make the conversion in the view - IMHO this is not against MVC. If you want to go hardcore with your design create a new class/struct "Gender" with static creation methods/properties "Male", "Female", overload the ToString accordingly and cast-operators to bool or a constructor with bool and a ToBool function.

Upvotes: 1

Related Questions