【发布时间】:2013-02-20 12:14:19
【问题描述】:
我有以下几点:
@foreach (var parent in Model.Parents)
{
@foreach (var child in parent.Children)
{
@Html.TextAreaFor(c => child.name)
}
}
如何让编辑对子对象起作用?我也尝试过这样的事情:
<input type="hidden" name="children.Index" value="@child.Id" />
<textarea name="children[@child.Id]" >@child.Name</textarea>
将 IDictionary 传递给控制器,但出现错误:
[InvalidCastException: Specified cast is not valid.]
System.Web.Mvc.CollectionHelpers.ReplaceDictionaryImpl(IDictionary`2 dictionary, IEnumerable`1 newContents) +131
这似乎是一项非常常见的任务...有没有简单的解决方案?我错过了什么?我需要使用编辑器模板吗?如果是这样,任何与 MVC4 兼容的示例都会很棒。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4