【发布时间】:2010-02-21 03:23:07
【问题描述】:
编辑:我正在尝试将包含列表的单个视图模型对象绑定到表单,以便帖子映射回相同的视图模型对象。
是否有任何代码可以在 MVC 2 中有效地做到这一点?
EditorFor( m => m, "Students", "Students[n]") // wrong but sorta close
// the third parameter specifies the ID of the html control
// ideally, the "Students[n]" could be a prefix for the inner fields
html 输出的位置:
<input id="Students[0]_Name" type="text" value="" />
<input id="Students[1]_Name" type="text" value="" />
<input id="Students[2]_Name" type="text" value="" />
id 程序集可能在部分“类”视图(UI 模板)中?
...
现在我想了想,我想知道这是否会在所有字段前面加上名称:
<% foreach( Student student in Model) { %><%
EditorFor( m => student, "Student",
"Students[" + Model.IndexOf(student) + "]" ) %><%
} %>
奇怪...这将第三个参数字符串(例如,“StuffHere”)放在学生和姓名之间:
id="Students_StuffHere_Name" name="Students.StuffHere.Name"
【问题讨论】:
标签: c# asp.net-mvc list templates