I have a IEnumerable ViewModel. This has the same names and I want to select only one name and display it in the header. Please suggest.
My code is a below. I am trying to use distinct but it does not work
@foreach (var item in Model.abc)
{
{
<table>
<tr>
<td style="width:100px" >@Html.Label("Name")</td>
<td style="width:225px"> @Html.DisplayTextFor(model => item.Name.Distinct())</td>
</tr>
</table>
}
}
To be more specific: my result will have only names {a,a,a,a,a} so I just want to pick the single {a} and display it.
If they all are the same and assuming
NameimplementsIEnumerableyou could try First:Update: add a new property to your model
Then: