在mvc中,当控制器类正确发送列表时,视图未收到列表

时间:2019-02-05 09:37:50

标签: asp.net-mvc-4

我正在从控制器发送列表以进行查看,但是尽管列表已填充在控制器中,但视图仍未收到

控制器:

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>

1 个答案:

答案 0 :(得分:0)

public class DepartmentController : Controller{
// GET: Department
public ActionResult Index() {
    EmployeeContext employeeContext = new EmployeeContext();
    List<Department> departments = 
    employeeContext.Departments.ToList();
    return View(departments);
}}