我在List Results中有一个类的结果集;格式
public class Result
{
public string StudentName {get; set;}
public string Subject {get; set;}
public string Marks {get; set;}
}
所以我想以这样的电子表格样式显示它。
在MVC View上显示它的最佳方法是什么?
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Subjects <span class="glyphicon glyphicon-arrow-right pull-right"></span></th>
@foreach (var sub in subjects)
{
<th>@sub</th>
}
</tr>
</thead>
<tbody>
@foreach (var item in students)
{
<tr>
<td>@item</td>
@for (int i = 0; i < subjects.Count(); i++)
{
var etc = Model.FirstOrDefault(m => m.StudentName == item && m.Subject == subjects.ElementAt(i));
<td>@etc.Marks</td>
}
</tr>
}
</tbody>
</table>
注意科目和学生是来自模型的不同()值