我知道这个问题已经被问了无数次,但请原谅我,因为我现在浪费了很多时间,因此终于发布了。所以总结一下,我有一个视图模型,它有一些复杂的类型属性和一个复杂的类型列表属性。
public class ViewModel
{
public ViewModel()
{
Gains = new List<Gain>();
}
[UIHint("Common")]
public AllRegRecordsLog commonRegisterFields { get; set; }
public Potential Potential { get; set; }
[UIHint("Gains")]
public List<Gain> Gains { get; set; }
public void CreateGains(int count = 1)
{
for (int i = 0; i < count; i++)
{
Gains.Add(new Gain());
}
}
}
现在我的视图 createOrEdit 我将此属性称为,
@Html.EditorFor(model => model.Gains)
我在我的特定视图文件夹中放置了一个编辑器模板
@model Gains
table id="gainsTable" class="content-tables"style="width:98%">
<tr id="defaultGainsRow">
<td class="editor-label">
@Html.LabelFor(model => model.VolumeGainLow)
</td>
<td class="editor-field">
@Html.TextBoxFor(model => model.VolumeGainLow)
@Html.ValidationMessageFor(model => model.VolumeGainLow)
</td>
</tr>
<tr>
<td colspan="4">
<input id="addGainsButton"type="button" class="t-button" Value="Add Potential Gains"/>
</td>
</tr>
</table>
但不知何故,我收到错误“传递到字典中的模型项是'System.Collections.Generic.List'类型,但需要增益”
我正在使用 asp.Net MVC 4
请指出我正确的方向。
谢谢
比拉尔