I am doing a project and got confused in a session that to retrieve phone number from db and must visible only the latest phone number based on date time. That is I have two field in db called phonenumber and datetime. I have got a many repeated phone number in different datetime. so what I need is to show phone number only twice than many with condition that only the most latest date is used (don't want to show the first entered number in db). I have written code for group by but it is not working and I didn't get the correct code for my problem

controller
 
 
C#
public async TaskActionResult> Index(string sortOrder, string CurrentSort, string currentFilter, string searchString, int? page, string FromDateString, string ToDateString)
C#
 {
C#
ViewData["FromDateString"] = FromDateString;
C#
 ViewData["ToDateString"] = ToDateString;
C#
int pageSize = 10; int pageIndex = 1;
C#
pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
C#
 ViewBag.CurrentSort = sortOrder;
C#
sortOrder = String.IsNullOrEmpty(sortOrder) ? "DateTime" : sortOrder;
C#
 IPagedListPhone> phones = null;
C#
 var List = db.Phones.OrderBy(t=>t.DateTime).ToList();
C#
foreach(var group in List.GroupBy(item => item.phoneNo))
C#
 {
C#
List = group.ToList();
C#
}
C#
if (!String.IsNullOrEmpty(searchString))
C#
 {
C#
List = List.Where(s => s.phoneNo.ToString().Contains(searchString)).ToList();
C#
}
C#
switch (sortOrder)
C#
{
C#
case "DateTime": if (sortOrder.Equals(CurrentSort))
C#
phones = List.OrderByDescending(m => m.DateTime).ToPagedList(pageIndex, pageSize); else
C#
 phones = List.OrderBy(m => m.DateTime).ToPagedList(pageIndex, pageSize);
C#
break;
C#
 case "Default":
C#
 phones = List.OrderBy(m => m.DateTime).ToPagedList(pageIndex, pageSize);
C#
 break;
C#
}
C#
 return View(phones);
C#
}
  view page
 
 
C#
table class="table">
C#
C#
C#
phoneNo
C#
 th>
C#
 DateTime th>
C#
 th>
C#
tr>
C#
 @foreach (var item in Model)
C#
{
C#
  @Html.DisplayFor(modelItem => item.phoneNo) td>
C#
 @Html.DisplayFor(modelItem => item.DateTime) td>
C#
@Html.ActionLink("Details", "Details", new { id = item.Id })
C#
 td> tr>
C#
 }
C#
C#
td colspan="6"> br />
C#
div style="text-align:left;"> Page @(Model.PageCount  Model.PageNumber ? 0 : Model.PageNumber)   of @Model.PageCount @Html.PagedListPager(Model, page => Url.Action("Index", new { page, currentFilter = ViewBag.CurrentFilter, sortOrder = ViewBag.sortOrder, ViewBag.FromDateString, ViewBag.ToDateString, ViewBag.searchString }))
C#
div> td>
C#
 br />
C#
td> tr>
C#
table>
 

this is the view page after going this it shows the actual means all the items from db and is not taking as group by

can anyone please help me to find the solution ???