asp.net-mvc-4 - 在 mvc 中,当控制器类正确发送列表时,视图没有接收到列表
问题描述
我正在从控制器发送一个列表到视图,但视图没有收到它,尽管控制器中填充了列表
控制器:
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>
解决方案
public class DepartmentController : Controller{
// GET: Department
public ActionResult Index() {
EmployeeContext employeeContext = new EmployeeContext();
List<Department> departments =
employeeContext.Departments.ToList();
return View(departments);
}}
推荐阅读
- python - 将字符串视为列表
- android-studio - 无法解析 Android Studio 上的原始符号错误
- html - PNG图像不显示透明
- rxjs - 保证发射之间的“n”秒,而无需最初等待
- c++ - cmake完成生成文件后如何自动制作
- wordpress - 在 functions.php 中使用 Composer 类
- android - 在编辑文本中按零任意次,但用户应该只能看到 1 位数字,例如计算器
- javascript - 如何正确使用 innerHTML 更改文本字段中的文本
- facebook-graph-api - Facebook 图形 api 发布状态
- mongodb - mongo-go-driver 投影数组长度