I have a controller class of Employee.Already the database is populated with records. Now there is a button for Bulk Insert in Index page. What i Want to do is:
1.When the Table view is loaded(please see the screenshot) and when it is clicked the cell should become editable.
2.Whatever the entry is put in it(the editable cell) should reflect back into original database(dbo.Employee),after clicking the Update button.It should perform Bulk Operation by calling action method name : BulkUpdateOrInsert in EmployeeController.cs
Below is the code and screenshots for reference.
Controller Method:
public ActionResult BulkUpdateOrInsert()
{
empRepo.BulkUpdateOrInsert();
return View();
}
The View File:
@model IEnumerable<Employee_Management_System.Models.Employee>
@{
ViewBag.Title = "BulkUpdateOrInsert";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>BulkUpdateOrInsert</h2>
<body>
<table id="myTableData" class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.City)
</th>
<th>
@Html.DisplayNameFor(model => model.Department)
</th>
<th>
@Html.DisplayNameFor(model => model.Gender)
</th>
<th>
@Html.DisplayNameFor(model => model.BulkUpdate)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@Html.DisplayFor(modelItem => item.Department)
</td>
<td>
@Html.DisplayFor(modelItem => item.Gender)
</td>
<td>
@Html.DisplayFor(modelItem => item.BulkUpdate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.EmployeeId }) |
@Html.ActionLink("Details", "Details", new { id = item.EmployeeId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.EmployeeId })
</td>
</tr>
}
</table>
@* @section{
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#myDataTable').dataTable().makeEditable();
});
</script>
}
*@
I have no idea how to make the Table View editable and how to get the updated values back in Action method so that insert can happen via stored procedure.
What I have tried:
Tried using SQLBulkCopy but i am not getting hang of it.Also went to look in MSDN but things seem much complicated.