我正在使用Grid.MVC来显示数据
我想在网格中创建动态列 在我看来,我将列显示如下
我正在通过IEnumerable<Student>
剃刀
@Html.Grid(Model).Columns(columns =>
{
columns.Add(c => c.Name).SetWidth(30).Titled("Student Name");
// i want to add for loop here to disply extra columns know at runtime
// the following doesn't work (want to replace ?? with
foreach (var task in ??.StudentTasks)
{
columns.Add(task.StudentSubject.Code).SetWidth(30).Titled("code"+uniq);
}
}
.CS
public class Student
{
public string Name { get; set; }
public IEnumerable<StudentTask> StudentTasks { get; set; }
}
public class StudentTask
{
public string TaskName { get; set; }
public Subject StudentSubject { get; set; }
}
public class Subject
{
public int Code { get; set; }
}