我使用EditorForModel()填充数据
指数法:
public ActionResult Index()
{
SampleDbContext db = new SampleDbContext();
return View(db.Employees.ToList());
}索引视图:
@model IEnumerable<MultipleRowsDemo.Models.Employee>
<div style="font-family:Aria">
@using (Html.BeginForm())
{
<table border="1">
<thead>
<tr>
<th>
Select
</th>
<th>
Name
</th>
<th>
Email
</th>
</tr>
</thead>
<tbody>
@Html.EditorForModel()
</tbody>
</table>
}
</div>但这是行不通的。它显示的数据如下
123选择姓名电子邮件
我读过类似的文章
EditorForModel and DisplayForModel do not work then passing class model within class model
建议不要使用复杂的属性。我没有。
另一个是。
Displaying entities data with EditorForModel
它建议使用
@using(Html.BeginForm())
{
...
}我已经有这个了。
发布于 2015-06-17 18:51:52
您的类实体名应该与模板的名称匹配,例如:如果您的ADO.net雇员实体名是" Employee“,那么在视图目录下的共享文件夹中,模板的名称应该是"Employee.cshtml”
https://stackoverflow.com/questions/22842521
复制相似问题