I am not able to display a table like this
classId class name frequency
1 basic one 2
2 basic two 1
I have a model like this to use to display frequency , classsId and class name. the classsId is a primary key in the class table and foreign key in the studentDetails table.className is in the class table
public int ClasssId { get; set; }
public int ClassCount { get; set; }
i create an action method to fetch data from the database and group
public ActionResult ClasssStatistics()
{
IQueryable<ClassStatistics> data = from st in db.StudentDetailss
group st by st.ClasssId into classsGroup
select new ClassStatistics()
{
ClasssId = classsGroup.Key,
ClassCount = classsGroup.Count()
};
return View(data.ToList());
}
and this is my view and the result i generate
<thead>
<tr>
<th>Class Id</th>
<th>Frequency</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr class="odd gradeX">
<td>@Html.DisplayFor(modelitem => item.ClasssId)</td>
<td>@item.ClassCount</td>
</tr>
}
</tbody>
result
classs Id frequency
1 2
2 1