开发者

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")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜