my Code is
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>
Create.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>}
in this code all thing is Ok , except name of array input no correct
I expect name=”KhorakTarkibVms[0].Percent”
but generated name is name=”KhorakTarkibVms.[0].Percent”
thanks for your help
1- you can’t use Array in this situations, instead use
List<>2- don’t need iterate
KhorakTarkibVmsso don’t needKhorakTarkibList.cshtmlSo this is new
TarkibVMclass:Don’t remember delete
KhorakTarkibList.cshtmlor rename it or removeUIhintAttribute.Don’t iterate
KhorakTarkibVms, So newCreate.cshtmlis:Add tr tag in new
KhorakTarkibVM.cshtml: