public class EmployeeController : Controller
{
//
// GET: /Employee/
public ActionResult Details(int id)
{
EmployeeContext employeeContext = new EmployeeContext();
Employee employee = employeeContext.Employees.SingleOrDefault(x => x.EmployeeId == id);
return View(employee);
}
}
//这里我只得到一行关于id ..如何从表中获取整行?我如何在视图页面上查看?
答案 0 :(得分:2)
要返回整个表格,只需选择整个表格而不是过滤。
Employee[] allEmployees = employeeContext.Employees.ToArray();
要在视图中显示它们,只需让视图的模型类型为数组,而不仅仅是单数Employee
。基本上只需制作模型Employee[]
。然后你可以循环遍历模型。
@model Employee[]
@foreach(var employee in Model)
{
// do something interesting
}