【发布时间】:2015-06-18 02:51:52
【问题描述】:
我正在使用 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())
{
...
}
我已经有了。
【问题讨论】:
-
我现在无法对此进行测试,但我认为
EditoForModel不应该适用于复杂对象的IEnumerable(即您创建的某个类的实例) )。保留此代码并在您的Views/Shared/EditorTemplates文件夹中创建一个Employee.cshtml(创建EditorTemplatesFolder,默认情况下它不存在)但如果您使用的是Areas,请将文件放在YourAreaName/Views/Shared/EditorTemplates中。还有一个 Views/Shared/DisplayTemplates Equivalent 用于显示模板。
标签: asp.net-mvc entity-framework razor