i have an html table inside a form in an asp.net mvc view. I am using the tablesorter jquery plugin as well.
Here is the table code (simplified for the example)
<table id=managersTable>
<thead>
<tr>
<th>Manager</th><th>Remove</th>
</tr>
</thead>
<tbody>
<tr>
<td>Manager 1<input type='hidden' name='updater.managers[0].Id' value=2313 /></td>
<tr>
<td>Manager 2<input type='hidden' name='updater.managers[1].Id' value=3233/></td>
<td><input type='button' class=removeButtonManager value='Remove' name='remove' /></td>
</tr>
</tbody>
so as you can see, there is a column with text and a second column with a button. I have it hooked up so when you click on the button it removed the row from the html table using this code:
$(document).ready(function() {
$(".removeButtonManager").live("click", function(event) {
var row = $(this).closest("tr").get(0);
$(this).closest("tr").remove();
$("#managersTable").trigger("update");
$("#managersTable").trigger("appendCache");
});
});
Everything works perfectly fine except one issue. When i click on a "remove" button it removed the row but the issue then is that the index for
name='updater.managers[0].Id'
is now off and it looks like in the latest version of asp.net mvc binding if you dont have your elements indexed property (0,1,2,etc . .) it doesn't bind.
so if i never delete a row it works perfectly as its 0,1,2 originally but if i delete the first row then i only have list (1,2 . .) and asp.net mvc wont bind this object.
so i am trying to figure out how i can reset the [] index in each of the elements after i remove a row so no matter if a remove any row, it always gives me a continuous list starting from 0.