Converting boolean values to text in mvc
I was wondering what is the best way to co开发者_如何学Pythonnvert 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?
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.
@((bool)item.BooleanColumn ? "Yes" : "No")
精彩评论