How to pass checked data to the controller after dynamically add data in table body
Opened this issue · 0 comments
amit018-hub commented
`
@{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
Employee Name:
@**@
Employee Branch:
Employee Salary:
</div>
<div class="col-md-2">
<button type="button" class="btn btn-outline-primary" id="btn-add" style="float:right; margin-top:0px;">Add More</button>
</div>
</div>
</div>
</div>
</div>
</div>
Employee Details
@*text-light*@
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
var count = 0;
$(function () {
$('#btn-add').click(function () {
debugger;
var rows = "";
count = count + 1;
var empname = $('#Emp_Name').val();
var empbranch = $('#Emp_Branch').val();
var empsalary = $('#Emp_Salary').val();
if (empname != "" && empbranch != "" && empsalary != "") {
rows += '' + empname + '' + empbranch + '' + empsalary + '';
$(rows).appendTo("tbody");
$('#Emp_Name').val("");
$('#Emp_Branch').val("");
$('#Emp_Salary').val("");
//var allVals = [empname, empbranch, empsalary];
//$('#secheck :checked').each(function () {
// allVals.push($(this).val());
//});
}
else {
alert("Field Empty");
}
});
});
$(function () {
$("#btnsumit").click(function () {
debugger;
var selected = new Array();
$("#tb input[type=checkbox]:checked").each(function () {
selected.push(this.value);
});
});
});
</script>
Check | Employee Name | Employee branch | Employee Salary |
---|
</div>
</div>
<div class="row mb-3">
<div class="col-md-10"></div>
<div class="col-md-2">
<button type="submit" id="btnsumit" class="btn btn-outline-success">Submit</button>
<button type="button" class="btn btn-warning waves-effect waves-themed" style="float:right;" onclick="location.href='@Url.Action("CreateEmp","Home")';">Cancel</button>
</div>
</div>
<p>Total Number Of Employees:<label></label></p>
<p>Total Salary:<label></label></p>
</div>
</div>
`