I have a form whereby I post a list of information.
So the list can be like so.
Person[0].FullName
Person[0].Address
Person[1].FullName
Person[1].Address
Person[2].FullName
Person[2].Address
Person[3].FullName
Person[3].Address
When I POST this information and run my update comment, it all works fine. The List<> model comes back with 4 records.
However, when I remove one of the middle records using jQuery, it removes the whole line from the HTML. So I end up with, for example, the scenario below.
Person[0].FullName
Person[0].Address
Person[2].FullName
Person[2].Address
Person[3].FullName
Person[3].Address
But now when I POST the information, the List<> count is now 1, because it's ignoring everything after the removal. I'm guessing it's because the List is now not sequential?
Has anyone come across the same issue before and know a way to save all items?
Thanks
EDIT - HTML
for (int i = 0; i < Model.PersonsViewModel.Count(); i++)
{
<div id="clone_@i" class="form-group clone">
<div class="col-sm-6 has-feedback">
<div class="row">
<div class="col-sm-12">
@Html.TextBoxFor(model => model.PersonsViewModel[i].FullName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.PersonsViewModel[i].FullName)
</div>
</div>
</div>
<div class="col-sm-6 has-feedback">
<div class="row">
<div class="col-sm-12">
@Html.TextBoxFor(model => model.PersonsViewModel[i].Address, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.PersonsViewModel[i].Address)
</div>
</div>
</div>
</div>
}