这个问题可能非常基本,但我对 C# 非常陌生。我从控制器返回列表数据而不使用模型。我想使用这个并想创建一个表。
// Mycontroller
public ActionResult Applied( string id)
{
try {
List<GrindersForJob> Grinders = JobAppliedRepository.GetgrindersByJobId(id);
return View(Grinders);
} catch (Exception ex) {
return View();
}
}
cshtml 文件=
@model IEnumerable<GrindersForJob>
<html>
<head>
<title>
</title>
</head>
<body>
@foreach(GrindersForJob item in Model)
{
<span>
@item.YourColumnName
</span>
}
</body>
</html>
只需将列表发送到您的视图即可
在视图顶部添加
@model IEnumerable<GrindersForJob>
现在您可以使用
foreach
循环在视图中迭代此列表
如果您想在表格中使用列表,为什么不将其作为表格传入呢?
正如已经提到的,@model IEnumerable 将获取您的列表
但是如果您需要一个表,您可以将 DataTable 传递给您的视图。
@模型系统.Data.DataTable