'Replace modelItem value of '0' with user friendly 'N'
I have an MVC5 C# web application.
My Index View brings back results in a table, using @foreach. Some of the fields are int and use 0 and 1 to designate No and Yes, respectively.
On the View, how do I display Y for 1 and N for 0 - to be more user friendly? I have tried replace, but can't seem to get it to work without errors.
Regular Code:
<b>Wailist F-Lot:</b> @Html.DisplayFor(modelItem => item.wait_E)
What I have tried (and failed):
<b>Wailist E-Lot:</b> @Html.DisplayFor(modelItem => item.wait_E.Replace(item.current_lot, 0, "N"))
The error I get is "int does not contain a definition for 'Replace'. Then what is the proper way to do this? or should it be handled in the model instead (and if so, how?)
Solution 1:[1]
in other to separate concerns, the best way is to add waitEstr string property to your model
public int wait_E
{
get { return waitEstr == "Y" ? 1: 0;}
set { waitEstr = value == 0 ? "N" : "Y" }
}
[NotMapped]
public string waitEstr { get; set;}
and view
<b>Wailist F-Lot:</b> @Html.DisplayFor(modelItem => item.waitEstr)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Serge |
