jeudi 6 août 2015

I am Passing array to the mvc controler but iam geting null

****Here is the jquery script. the takes value from table and pass it to object****

$(document).ready(function () {
                var table = $('#example').DataTable();

                $('#example tbody').on('click', 'tr', function () {
                    $(this).toggleClass('selected');
                });

                $('#button').click(function () {
                    debugger;
                    var Data = [];
                    var TableData = $.map(table.rows('.selected').data(), function (item) {


                        var objData = {};
                        objData.Name = item[0]
                        objData.Position = item[1]
                        objData.Office = item[2]
                        objData.Age = item[3]
                        objData.Startdate = item[4]
                        objData.Salary = item[5]

                        var objparsed = $.makeArray(objData);

                        for (var x in objparsed) {
                            Data.push(objparsed[x]);
                        }

                    });

                    alert(Data);
                    $.ajax({
                        data: JSON.stringify({ 'Data': Data }),
                        url: '/Table/SelectedTable',
                        dataType: "json",
                        type: 'POST',`enter code here`
                        contentType: "application/json; charset=utf-8",


                    });
                });
            });

******Here is the contoler code the value her returns null** **I am Passing array to the mvc controler but iam geting null****

 [HttpPost]
                public ActionResult SelectedTable(string[] Data)
                {

                    Models.SelectedTable select = new Models.SelectedTable();
                    select.Name = Data[0];
                    select.Position = Data[1];
                    select.Office = Data[2];
                    select.Age = Data[3];
                    select.Startdate = Data[4];
                    select.Salary = Data[5];
                    return View(Data);
                }

Aucun commentaire:

Enregistrer un commentaire