You could use javascript to dynamically create indexed inputs for post back. As an example create a dummy set of inputs that are cloned and displayed when you click an 'add pet' button (assumes Pet properties are displayed in a table with id='Pets')
<div id="NewPet" style="display:none">
<tr>
<td><input type="text" name="Pets[#].Type value /></td>
<td><input type="text" name="Pets[#].Breed value /></td>
<td>.....</td> // more properties of Pet
<td><input type="hidden" name="Pets[#].Index" value ="%"/></td>
</tr>
</div>
Note the use of a dummy indexer to prevent this one being posted back
And the script
$('#AddButton').click(function() {
var index = (new Date()).getTime();
var clone = $('#NewPet').clone();
// Update the index of the clone
clone.html($(clone).html().replace(/[#]/g, '[' + index + ']'));
clone.html($(clone).html().replace(/"%"/g, '"' + index + '"'));
$('#Pets tbody').append(clone.html());
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…