我的问题是如何将所有输入保存到数据库中。因为我对此一无所知,任何人都可以帮我解决这个问题 如何获取所有数据以及如何将数据从视图传递到控制器 任何人都可以解释如何将动态文本框值传递给控制器
Here is my Design:
<div class="container" style="background-color:lightblue">
<h2>Family Details</h2>
<table class="table" id="maintable" style="border:solid">
<thead style="border-color:blue">
<tr>
<th>Name</th>
<th>Date Of Birth</th>
<th>Relation</th>
<th>Occupation</th>
</tr>
</thead>
<tbody>
<tr class="data-contact-person">
<td>
<input type="text" name="fname" class="form-control f-name01" /></td>
<td>
<input type="text" name="fdob" class="form-control l-name01" /></td>
<td>
<input type="text" name="frelation" class="form-control email01" /></td>
<td>
@Html.DropDownListFor(model => model.occupation_id, Model.OccupationSelectList, "-----Select-----", new { })
</td>
<td>
<button type="button" id="btnAdd" class="btn btn-xs btn-primary classAdd">Add More</button>
</td>
</tr>
</tbody>
</table>
<button type="button" id="btnSubmit" class="btn btn-primary btn-md pull-right btn-sm">Submit</button>
</div>
Here Is MY Script:
<script>
$(document).ready(function () {
$(document).on("click", ".classAdd", function () {
var rowCount = $('.data-contact-person').length + 1;
var cc = $("#occupation_id").html();
var contactdiv = '<tr class="data-contact-person">' +
'<td><input type="text" name="fname' + rowCount + '" class="form-control f-name01" /></td>' +
'<td><input type="text" name="fdob' + rowCount + '" class="form-control l-name01" /></td>' +
'<td><input type="text" name="frelation' + rowCount + '" class="form-control email01" /></td>' +
'<td><select name="occupation_id" id="occupation_id ' + rowCount + '">' + cc + '</select></td>' +
//'<td><button type="button" id="btnAdd" class="btn btn-xs btn-primary classAdd">Add More</button>' +
'<td><button type="button" id="btnDelete" class="deleteContact btn btn btn-danger btn-xs">Remove</button></td>' +
'</tr>';
$('#maintable').append(contactdiv);
});
});
</script>
<script>
$(document).on("click", ".deleteContact", function () {
$(this).closest("tr").remove();
});
</script>