EDIT:
I've a table with which I dynamically add / remove rows in a table using jQuery in MVC4. When I do POST the rows are not stored completely,
Example: I add 10 rows to the table and delete the 7th, theoretically there are only 9 rows left. The problem I have is that regardless of the row that I delete, only the rows before that (1 to 6) are saved and it is supposed to save all the rows that are in the table (1 to 9).
I was looking for debbug and noticed that the Input ID is not updated, I got the following results.
<input name="[0].HW_SQ">
<input name="[1].HW_SQ">
<input name="[2].HW_SQ">
<input name="[3].HW_SQ">
<input name="[4].HW_SQ">
<input name="[5].HW_SQ">
<input name="[7].HW_SQ">
<input name="[8].HW_SQ">
<input name="[9].HW_SQ">
As you can see, the position I selected was eliminated but the input ID was not updated, so I need it to be as follows.
<input name="[0].HW_SQ">
<input name="[1].HW_SQ">
<input name="[2].HW_SQ">
<input name="[3].HW_SQ">
<input name="[4].HW_SQ">
<input name="[5].HW_SQ">
<input name="[6].HW_SQ">
<input name="[7].HW_SQ">
<input name="[8].HW_SQ">
Is there any way to update the id values correctly?
Here's my code:
<div><a href="#" id="addNew"><input type="button" value="Add"/></a></div>
<table id="dataTable">
<thead>
<tr>
<th>#</th>
<th>SEQ</th>
<th>Brand</th>
<th>Serial</th>
<th>Model</th>
<th>Year Model</th>
<th>Status</th>
<th>Place</th>
<th>Location</th>
<th>FA Tag</th>
<th>Security Tag</th>
<th>Date Acquisition</th>
<th>Price</th>
<th>Description</th>
</tr>
</thead>
<tbody id="mytbody">
@if (Model != null && Model.Count > 0)
{
int j = 0;
int index = 1;
foreach (var p in Model)
{
<tr>
<td style="text-align:center;">@index</td>
<td>@Html.TextBoxFor(a => a[j].HW_SQ)</td>
<td>@Html.TextBoxFor(a => a[j].HW_BRAND)</td>
<td>@Html.TextBoxFor(a => a[j].HW_SERIAL)</td>
<td>@Html.TextBoxFor(a => a[j].HW_MODEL)</td>
<td>@Html.TextBoxFor(a => a[j].HW_YEAR)</td>
<td>@Html.TextBoxFor(a => a[j].HW_STATUS)</td>
<td>@Html.TextBoxFor(a => a[j].HW_PLACE)</td>
<td>@Html.TextBoxFor(a => a[j].HW_LOCATION)</td>
<td>@Html.TextBoxFor(a => a[j].HW_FA_TAG)</td>
<td>@Html.TextBoxFor(a => a[j].HW_SECURITY_TAG)</td>
<td>@Html.TextBoxFor(a => a[j].HW_DATE_ITEM_ADQUISITION)</td>
<td>@Html.TextBoxFor(a => a[j].HW_PRICE)</td>
<td>@Html.TextBoxFor(a => a[j].HW_DESCRIPTION)</td>
<td>
<a href="#" id="remove" class="remove">Remove</a>
</td>
</tr>
index += 1;
}
}
</tbody>
</table>
<center><input type="submit" value="Save" id="sendinv"/></center>
jQuery Code:
$(document).ready(function () {
function numberRows($t) {
$t.find("tr").each(function (i, el) {
$(el).find("td").eq(0).html((i + 1));
});
}
//- Start Table Add, delete buttons -
$("#addNew").click(function (e) {
e.preventDefault();
var last = $('#dataTable>tbody>tr:last');
if (last.length > 0) {
var name = last.children().find('input,select')[0].name;
var index = Number(name.replace(/[^0-9]/gi, '')) + 1;
var tr = ('<tr>' + last.html().replace(/[0-9]+__/gi, index + '__') + '</tr>').replace(/\[[0-9]+\]+[.]/gi, '[' + index + '].');
numberRows($('#dataTable tbody').append(tr));
}
});
$(document).on('click', '#remove', function (e) {
e.preventDefault();
if ($('#dataTable>tbody>tr').length > 1) {
//$(this).parent().parent().remove();
$(this).closest('tr').remove();
numberRows($('#dataTable tbody'));
return false;
}
else {
//$(this).parent().parent().show();
alert('Form must have at least one row')
numberRows($('#dataTable tbody'));
}
});
//- End Table Add, delete buttons -
});

#removebutton, but the picture you're showing suggests that you have multiple "remove" buttons. If you're re-usingidvalues on the page then your markup is invalid anyway and you'll want to correct that before debugging anything else.