I have a bit of code, that while simple perhaps isn't immediately obvious as to what it does.
I found @(Model.Count() == 0 ? "no" : Model.Count().ToString()) @(Model.Count() == 1 ? "person" : "people")
@foreach (var item in Model) {
<div>@item.Name at @item.Email</div>
}
And before I write lots of code like this, I wanted to know if this is a good way of doing this.
Thus the question is, in .NET is there a better framework way of doing this, or is the Ternary method fine
The premise is obviously
- 0 records = I found no people
- 1 record = I found 1 person
- 2+ records = I found 2 people