Hello All,
I am having a bit of a struggle using linq and returning a list while trying to group.
In my view, I have the following:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcApplication1.Models.Log>>" %>
<table>
<tr>
<th>
ID
</th>
<th>
User
</th>
<th>
NumberDialed
</th>
<th>
Date
</th>
<th>
Time
</th>
<th> </th>
</tr>
<% foreach (var item in Model)
{ %>
<tr>
<td>
<%: item.ID %>
</td>
<td>
<%: item.UserName %>
</td>
<td>
<%: item.NumberDialed %>
</td>
<td>
<%: item.Date %>
</td>
<td>
<%: item.Time %>
<%} %>
</td>
</table>
and in my controller I have:
public ActionResult Tenant()
{
LogEntities db = new LogEntities();
var s = from logs in db.Logs
group logs by logs.UserName;
return View(s.ToList());
}
when I do a normal select it works:
public ActionResult Tenant()
{
using (LogEntities db = new LogEntities())
{
var s = from logs in db.Logs
orderby logs.UserName
select logs;
return View(s.ToList());
}
}
Why is using Group By not working and why it is so different? I want to be able to display the data by groups. How do I accomplish this?
Thanks :)