我的代码是
public class TarkibVM:BaseVM
{
public int TarkibID { get;set;}
[UIHint("KhorakTarkibList")]
public KhorakTarkibVM[] KhorakTarkibVms { get; set; }}
public class KhorakTarkibVM
{
public int KhorakID{ get;set;}
public string Name{ get;set;}
}
KhorakTarkibList.cshtml :
@model MvcMarkazToyoor.Models.KhorakTarkibVM[]
<table>
@for (int index = 0; index < Model.Count(); index++)
{
<tr>
@Html.EditorFor(modelItem => modelItem[index])
</tr>
}
</table>
KhorakTarkibVM.cshtml :
@model MvcMarkazToyoor.Models.KhorakTarkibVM
<td>
@Html.EditorFor(modelItem => modelItem.Checked)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.KhorakID)
@Html.HiddenFor(modelItem => modelItem.KhorakID)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.Name)
</td>
创建.cshtml:
@model MvcMarkazToyoor.Models.TarkibVM
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<div class="editor-label">
@Html.LabelFor(model => model.GroupID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.TarkibID)
@Html.ValidationMessageFor(model => model.TarkibID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.KhorakTarkibVms)
</div>
<p>
<input type="submit" value="Create" />
</p>}
在这段代码中一切正常,除了数组输入的名称不正确我期望 name="KhorakTarkibVms[0].Percent" 但生成的名称是 name="KhorakTarkibVms.[0].Percent"
感谢您的帮助