我正在从控制器发送列表以进行查看,但是尽管列表已填充在控制器中,但视图仍未收到
控制器:
public class DepartmentController : Controller
{
// GET: Department
public ActionResult Index() {
EmployeeContext employeeContext = new EmployeeContext();
List<Department> departments =
employeeContext.Departments.ToList();
return View();
}
}
查看:
@model IEnumerable<MVCDemo.Models.Department>
@using MVCDemo.Models;
@{
ViewBag.Title = "Departments List";
}
<div style="font-family:Arial">
<h2>Departments List</h2>
<ul>
@foreach (Department Department in @model) {
<li>@Html.ActionLink(Department.name, "Index","Employee", new {
departmentid = Department.ID })</li>
}
</ul>
</div>
答案 0 :(得分:0)
public class DepartmentController : Controller{
// GET: Department
public ActionResult Index() {
EmployeeContext employeeContext = new EmployeeContext();
List<Department> departments =
employeeContext.Departments.ToList();
return View(departments);
}}