user10190650
user10190650

Reputation:

ASP.NET Convert true/false to Yes/No

I am new in ASP.NET and I am trying to convert True/False value to Yes/No.

 <th>
   Arbitration
 </th>

<td>
   @Html.DisplayFor(modelItem => item.Arb)
</td>

What is the best way to do it ?

Upvotes: 0

Views: 531

Answers (1)

Marcus H&#246;glund
Marcus H&#246;glund

Reputation: 16811

One option is to use an extension

NFdocs.Models 
{ 
    public static class BoolExt 
    { 
        public static string ToYesNo(this bool? val) => (val ?? false) ? "Yes" : "No"; }
    }
}

Then in view

@using NFdocs.Models 

<span>@item.Arb.ToYesNo()</span>

Upvotes: 2

Related Questions