Я использую Dynami c Добавление и удаление столбца, все работает нормально, если я удаляю последнюю строку, но если я удаляю первый индекс, тогда он теряет все остальные строки.
Но если я использую FormCollection, его привязка, но не как список массивов
public ActionResult Index()
{
var employee = new Employee();
employee.Skills.Insert(0, new Skill());
return View(employee);
}
.cs html
<table id="skills-table">
<thead>
<tr>
<th style="width:20px;"> </th>
<th style="width:160px;">Skill</th>
<th style="width:150px;">Level</th>
<th style="width:32px;"> </th>
</tr>
</thead>
<tbody>
@for (var j = 0; j < Model.Skills.Count; j++)
{
<tr valign="top">
<th><span class="rownumber"></span></th>
<td>
@Html.TextBoxFor(model => model.Skills[j].Title, new { @class = "skill-title" })
@Html.ValidationMessageFor(model => model.Skills[j].Title)
</td>
<td>
@Html.DropDownListFor(
model => model.Skills[j].Level,
new SelectList(WebApplication4.MetaModels.SkillLevel.GetSkillLevels(), "Code", "Description", Model.Skills[j].Level),
"-- Select --",
new {@class = "skill-level"}
)
@Html.ValidationMessageFor(model => model.Skills[j].Level)
</td>
<td>
@if (j < Model.Skills.Count - 1)
{
<button type="button" class="remove-row" title="Delete row"> </button>
}
else
{
<button type="button" class="new-row" title="New row"> </button>
}
</td>
</tr>
}
</tbody>
</table>
jQuery:
Контроллер:
public ActionResult Index(Employee employee, FormCollection abc, string[]dynamic)
{
return View(employee);
}
Здесь мой FormCollection
получает все данные, но не как тип массива