asked on
<div>
<table class="table table-condensed" id="people-list">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
</tr>
</thead>
<tbody>
@for (var i = 0; i < Model.PeopleList.Count; i++)
{
<tr>
<td>
@Html.HiddenFor(m => Model.PeopleList[i].FirstName)
@Html.TextBoxFor(m => Model.PeopleList[i].FirstName, new { @class = "row-index form-control"})
</td>
<td>
@Html.HiddenFor(m => Model.PeopleList[i].LastName)
@Html.TextBoxFor(m => Model.PeopleList[i].LastName, new { @class = "form-control" })
</td>
<td>
@Html.HiddenFor(m => Model.PeopleList[i].Email)
@Html.TextBoxFor(m => Model.PeopleList[i].Email, new { @class = "form-control" })
</td>
<td>
<button class="btn btn-default" id="remove-person-@i"><i class="glyphicon glyphicon-minus"></i></button>
</td>
</tr>
}
</tbody>
</table>
</div>
<div>
<div class="btn-group">
<button type="button" class="btn btn-primary" id="add-person"><i class="glyphicon glyphicon-plus"></i>Add Person</button>
<br/><br/>
</div>
</div>
$("#add-person").click(function() {
var i = $(".row-index").length;
$.ajax({
url: "people/AddPerson?index=" + i,
success: function (data) {
$('#people-list > tbody').append(data);
},
error: function (a, b, c) {
console.log(a, b, c);
}
});
});
<tr>
<td>
<input id="People_@(ViewBag.Index)__FirstName" name="People[@(ViewBag.Index)].FirstName" type="hidden" value="Bob">
<input id="People_@(ViewBag.Index)__FirstName" name="People[@(ViewBag.Index)].FirstName" type="text" value="Bob" class="form-control">
</td>
<td>
<input id="People_@(ViewBag.Index)__LastName" name="People[@(ViewBag.Index)].LastName" type="hidden" value="Smith">
<input id="People_@(ViewBag.Index)__LastName" name="People[@(ViewBag.Index)].LastName" type="text" value="Smith" class="form-control">
</td>
<td>
<input id="People_@(ViewBag.Index)__Email" name="People[@(ViewBag.Index)].Email" type="hidden" value="bsmith@yopmail.com">
<input id="People_@(ViewBag.Index)__Email" name="People[@(ViewBag.Index)].Email" type="text" value="bsmith@yopmail.com" class="form-control">
</td>
<td>
<button class="btn btn-default" id="remove-person"><i class="glyphicon glyphicon-minus"></i></button>
</td>
</tr>