How to generically format a boolean to a Yes/No string?

前端 未结 4 1340
萌比男神i
萌比男神i 2020-11-30 09:53

I would like to display Yes/No in different languages according to some boolean variable.
Is there a generic way to format it according to the locale passed to it?
I

4条回答
  •  执笔经年
    2020-11-30 10:19

    in my razor page is working this: @(item.Active.GetValueOrDefault() ? "Yes" : "No")

    here is important if attribute is required (nullable) or not, if is required it should be good with:

    @(item.Active ? "Yes":"No")
    

    I found this here on some other post, just replaying, hope it helps some1.

提交回复
热议问题