Q:

MVC, Only show first item for each different Name in foreach loop

I have a list containing 6 items (rows). First column gives the property "Name" in each row:

Name
item1
item1
item1
item2
item2
item2

Is it possible to use a foreach loop to only show the first item of each different name so I get something like this:

item1
item2

I have tried using Model.Take(1) but this only shows the first item in the entire list.
My current loop looks like this:
foreach (var item in Model)
    {
        <p>@Html.DisplayFor(modelItem => item.Name)</p>
    }

A:

You need grouping:
@{
   var result = Model.GroupBy(x=>x.Name);

}

and then iterate on result for rendering.
@foeach(var item in result)
{
  <span>@item.Key</span>
}

