Click here to Skip to main content
14,330,776 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have created JQuery Datatable to load the multiple records after page loads.
During edit the row after click or keypressed the specified row, the specified rows values is initiated into new edit view through parameter id value.

But not shown the id value on controller parameterized function.

The value of id is display in view during debugging mode,but when call the controller function the passing id value is not display in controller function.
why???? i do not know..

Can any body help for above problems????
PLease........

What I have tried:

My cshtml code is below:
            $(document).ready(function () {
                $.noConflict();
                $.ajax({
                    url: 'Unit/GetUnit',
                    method: 'post',
                    dataType: 'json',
                    success: function (data) {
                        $('#datatable').DataTable({
                            select: {
                                //style: 'single'
                            },
                            keys: true,
                            data: data,
                            paging: false,
                            searching: false,
                            ordering: false,
                            
                            scrollY: 200,
                            columns: [
                                {
                                    data: 'UnitID',
                                    width: '10px'
                                },
                                {
                                    data: 'Name',
                                    width: '300px',
                                    //searchable: false,
                                    //orderable:false
                                },                                    },
                            ],
                            columnDefs: [
                                { className: 'dt-body-center', targets: [0] },//"UnitID"
                                { visible: false, targets: [0] },
                                { className: 'dt-body-left', targets: [1] }//"Name"
                            ]
                        });
                    }
                });
                KeyEventHandler();
            });

            function KeyEventHandler() {
                $('#datatable').on('key', function (e, datatable, key, cell, originalEvent) {
                    if (key == 13) {
                        var tbl = $('#datatable').DataTable();
                        var pID = tbl.row('tr').data()['UnitID'];

                        //window.location.href = "/Unit/Edit?UnitID =" + encodeURIComponent(pID) + "";
                        //window.location.href = "Create";
                        EditRow(pID);
                    }
                });
        }
        function EditRow(id) {
            if (confirm("Are You sure to edit this record..?")) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("Edit", "Unit")',
                    data: { id: id },
                    datatype: 'json',
                    success: function (response) {
                        // do something with response
                        alert("Successfully updated.");
                    },
                    error: function (msg) {
                        alert(msg.responseText);
                    }
                });
            }
        }

My controller code is below:
        public ActionResult Edit(Int16? uID = null)
        {
            string cs = ConfigurationManager.ConnectionStrings["MainCon"].ConnectionString;
            List<modUnit> mUnits = new List<modUnit>();
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("Select * From acM_Unit Where UnitID =" + uID, con);
                cmd.CommandType = CommandType.Text;
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    modUnit unit = new modUnit();
                    unit.UnitID = Convert.ToInt32(rdr["Unitid"]);
                    unit.Name = rdr["Name"].ToString();
                    mUnits.Add(unit);
                }
            }
            return View(mUnits);
        }
Posted

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100