Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
public ActionResult BulkUpdateOrInsert()
       {
          empRepo.BulkUpdateOrInsert();
          return View();
       }




The View File:

C#
@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.
Posted
Updated 4-Dec-19 11:25am
v2
Comments
F-ES Sitecore 4-Dec-19 11:23am    
I'd start by googling "c# mvc editable table ajax" to get an appreciation for what is involved, and you'll probably find plenty of complete code samples too.

https://www.codeproject.com/Articles/165410/ASP-NET-MVC-Editable-DataTable-jQuery-DataTables-a
chaturvedi_anshumaan_20191 4-Dec-19 12:57pm    
Google can't answer sometimes all the problems. And i may not be able to decipher also.So,i have put my faith here.
chaturvedi_anshumaan_20191 5-Dec-19 6:30am    
Anyone has faced this in real life pls do help me out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900