Ramu D

Ramu D

  • NA
  • 5
  • 23.1k

How to get Row data from Jqgrid to another view/Controller

May 24 2013 6:31 AM
Hii to all,
   I Have a requirement that i need to retrive  one r more table's data from DataBase (SQLServer)& display in a Jqgrid.Up to here i have done using Linq Joins&EntityFramework,and one more requirement where i strucked is,here in Jqgrid i have made Multiselect to True,after displaying the table data in Jqgrid the respective checked row's data i need to get in another view say Editable view where i need to dispaly this row data in Textboxes in Editable mode,here user will update the records present in Textboxes and when he press Updata button,the records should be updated to DataBase& also we need to redirect to previous View(after clicking update button in Editable View)
 i.e Jqgrid view & display the modified records in Jqgrid.
Here is my Jqgrid View code  say "GetTablesData":-
@model MVCLINQJoins.Models.TableData
<link href="@Url.Content("~/Content/themes/base/ui.jqgrid.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/JS/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/JS/jquery.jqGrid.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/JS/grid.locale-en.js")" type="text/javascript"></script>
@{
    ViewBag.Title = "GetTablesData";
}
<h2>
    GetTablesData</h2>
<script type="text/javascript">
    var mdata = []
</script>
@foreach (var item in Model.getEmployeeDetails)
{
    <script type="text/javascript">
        row = { EmployeeID: '@item.EmployeeId', EmpName: '@item.EmpName', Designation: '@item.Designation', Salary: '@item.Salary', MobileNo: '@item.MobileNo', Email: '@item.Email' };
        mdata.push(row);
    </script>
}
<table id="emp-data-grid">
</table>
<script type="text/javascript">
    $("#emp-data-grid").jqGrid({
        datatype: "local",
        data: mdata,
        colNames: ["EmployeeID", "EmpName", "Designation", "Salary", "MobileNo", "Email"],
        colModel: [
                { name: "EmployeeID", index: "EmployeeID", editable: true, edittype: "checkbox", editoptions: { value: "Yes:No"} },
                { name: "EmpName", index: "EmpName" },
                { name: "Designation", index: "Designation" },
                { name: "Salary", index: "Salary", sorttype: "int" },
                { name: "MobileNo", index: "MobileNo", sorttype: "int" },
                { name: "Email", index: "Email" }
            ],
        shrinkToFit: true,
        multiselect:true,
        caption: "Employee List"
 
    });
 

</script>
    @Html.ActionLink("EDIT", "Edit")
when he click on above Edit link,i need to get the respective rows data to Edit View.
Here is My Controller Code:-
public ActionResult GetTablesData()
        {
            TableData model = new TableData();
            model.getEmployeeDetails = new List<Employee>();
            GetDataFromDB(model);
            return View(model);
        }
 
        private static void GetDataFromDB(TableData model)
        {
            using (personalEntities2 db = new personalEntities2())
            {
                var emply = (from empd in db.empdetails
                             join empp in db.emppersonals on empd.empid equals empp.empid
                             orderby empd.empid
                             select new
                             {
                                 empd.empid,
                                 empd.ename,
                                 empd.designation,
                                 empd.salary,
                                 empd.deptno,
                                 empp.mobileno,
                                 empp.email
                             });
                foreach (var item in emply)
                {
                    Employee ed = new Employee();
                    ed.EmployeeId = item.empid;
                    ed.EmpName = item.ename;
                    ed.Designation = item.designation;
                    ed.Salary = item.salary;
                    ed.DeptNo = item.deptno;
                    ed.MobileNo = item.mobileno;
                    ed.Email = item.email;
                    model.getEmployeeDetails.Add(ed);
                }
 
            }
        }
        public ActionResult Edit(Employee model,int id)
        {
 
          return View(model);
        }
Please guide me how to achieve my requirement along with Controller code.Thanks in advance
 
Thanks
Ramu