我有一个从视图模型填充的视图,其中一个属性是复杂类型的集合。视图正确呈现,列表正在迭代到一个表中,每个项目还没有被选中。当我提交表单时,我无法将对象列表返回到模型中,我无法弄清楚我做错了什么。集合中的每个项目被添加到如下的观点:集合不在模型中返回
@for (int i = 0; i < Model.Items.Count; i++
var rowClass = "selectRow";
if (item.IsSelected)
{
rowClass = "success";
}
<tr class="@rowClass">
@Html.HiddenFor(m => m.Items[i].PropertyOne)
<td>
@Html.DisplayFor(m => m.Items[i].PropertyTwo)
</td>
<td class="actions">
// only those items not previously selected need a radio button
@if (item.IsSelected == false)
{
@Html.RadioButtonFor(m => m.Items[i].IsSelected, m.Items[i].PropertyOne, new { id = "IsSelected_" + m.Items[i].PropertyOne })
}
</td>
</tr>
}
我已经使用@ Html.HiddenFor(X => x.PropertyOne)尝试,但我不能选择的值的集合结合回到模型。我可以使用隐藏字段返回模型中的所有其他内容,但我不知道如何解决此问题。任何帮助表示赞赏。
感谢
找出这里发生了什么的最好方法是查看发布时线路上有哪些Model.Items。你使用过提琴手吗? http://www.telerik.com/fiddler。还是FireBug? –