@model HelloWorldMvcApp.PersonListVM
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
.field-validation-error {
border-collapse:collapse;
border-bottom: solid 1px gray;
background: rgba(0,0,0,0.1);
margin: -100px 0 0 -200px;
<th>@Html.DisplayNameFor(m => m.FirstName)</th>
<th>@Html.DisplayNameFor(m => m.LastName)</th>
@foreach (var person in Model.People)
<td class="firstname">@person.FirstName</td>
<td class="lastname">@person.LastName</td>
<td><a href="#" data-id=@person.ID class="edit">Edit</a></td>
<a href="#" id="create">Add new person</a>
<div class="col-md-6 col-md-offset-3">
@Html.HiddenFor(m => m.ID)
@Html.LabelFor(m => m.FirstName)
@Html.TextBoxFor(m => m.FirstName, new {@class="form-control"})
@Html.ValidationMessageFor(m => m.FirstName)
@Html.LabelFor(m => m.LastName)
@Html.TextBoxFor(m => m.LastName, new {@class="form-control"})
@Html.ValidationMessageFor(m => m.LastName)
<button type="button" id="save" class="btn btn-success submit">Save</button>
<button type="button" id="cancel" class="btn btn-success submit">Cancel</button>
<td class="firstname"></td>
<td class="lastname"></td>
<td><a href="#" class="edit">Edit</a></td>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/mvc/4.0/jquery.validate.unobtrusive.min.js"></script>
<script type="text/javascript">
var url = '@Url.Action("Save")';
var dialog = $('#dialog-mask');
var template = $('#template');
$('#create').click(function() {
$('#table').on('click', '.edit', function() {
currentRow = $(this).closest('tr');
$('#ID').val($(this).data('id'));
$('#FirstName').val(currentRow.find('.firstname').text());
$('#LastName').val(currentRow.find('.lastname').text());
$('#save').click(function() {
$.post(url, form.serialize(), function(data) {
if (currentRow == null) {
var row = template.clone();
row.find('.firstname').text($('#FirstName').val());
row.find('.lastname').text($('#LastName').val());
row.find('.edit').data($('id', data.ID));
table.append(row.find('tr'));
currentRow.find('.firstname').text($('#FirstName').val());
currentRow.find('.lastname').text($('#LastName').val());
$('#cancel').click(function() {