首页 > 解决方案 > Push one Row from Table 1 to table 2 and Splice the same row from Table 1 and vice-versa

问题描述

I have created a Method GetOpPriv() in the Home Controller which retrieves a JSON from a stored procedure. I have two tables on the Index View id='table1' & 'table2' I have Displayed the JSON values on 'table1' using JQuery Ajax. Now, I want to select rows from table1 and send those JSON values to table2 on click of a button. On click of 1st button, the value should be sent to table2 and the same value should be spliced from table1 and vice versa for the 2nd button. How can I do the Push and splice at the same time?

Home Controller

 public JsonResult GetOpPriv()
    {
        using (MvcAssignmentEntities db = new MvcAssignmentEntities())
        {            
            var op =( from data in db.OPERATION_PRIVILEGE()
                          select new 
                          {
                              OperationName = data.OperationName,
                              PrivilegeName = data.PrivilegeName
                          }).ToList();

            return Json(op, JsonRequestBehavior.AllowGet);
        }
    }

JQuery Ajax

<script type="text/javascript">
    $(document).ready(function () {
        debugger;
        $.ajax({
            url: "/Home/GetOpPriv",
            type: "GET",
            contentType: "application/json; charset=utf-8",
            data: "{}",
            dataType: "json",
            success: function (data) {
                var row = "";
                $.each(data, function (index, item) {
                    row += "<tr><td>" + item.PrivilegeName + "</td>" + "<td>" + item.OperationName + "<td>";
                });
                $("#table1").html(row);
            },
            error: function (result) {
                alert("Error");
            }
        })
    });

</script>
<caption class="display-4">Available Privilege:</caption>
<table class="table-bordered" style="float: left" id="table1">
    <thead>
        <tr>
            <th>Operation </th>
            <th>Privilege Name</th>
        </tr>
    <tbody></tbody>
</table>

标签: javascriptjqueryasp.netajaxmodel-view-controller

解决方案


推荐阅读