0

Below is my Js code

 function Table_to_Array() {
    var myTableArray = $("#tbl_CGT tr").map(function () {
        return $(this).find(':input').map(function () {
            return this.value;
        }).get();
    }).get();
    return myTableArray;
}

function send_to_server()
{
    var result = Table_to_Array();
    //var data = {
    //    Array: result
    //};

    var params = {
        url: '@Url.Action("test2", "Annex1")',
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        traditional : true,
        //data: JSON.stringify(data),
        data: {Array:JSON.stringify(result)},
        success: function (result) { alert('Ok! It worked.'); },
        error: function (result) { alert('Warning! It failed.'); }
    };
    $.ajax(params);
}

It convert table values into an array and pass it to ActionResult in controller

It is creating array very well

Click Here

But in controller it is coming null

public ActionResult test2(string[] Array)
    {
        string val = Array[1].ToString();
        return View("Index");
    }

What changes I need to do in it

  • Why dont you use Model ? BDW change string[] to List – Rush.2707 Aug 09 '17 at 10:26
  • In your controller action `string[] Array`,`Array` needs to be the same name as in Js –  Aug 09 '17 at 10:26
  • @IrshadJm he has same name "Array" .... But he should change that name also – Rush.2707 Aug 09 '17 at 10:28
  • 1
    yes, he can not give `Array` as name –  Aug 09 '17 at 10:29
  • Ok , I changed the name to data_holder and it is sending data now , but still alert in error statement is still executing and showing alert('Warning! It failed.'); –  Aug 09 '17 at 10:35
  • Possible duplicate of [How can I post an array of string to ASP.NET MVC Controller without a form?](https://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form) – Igor Aug 09 '17 at 11:23

0 Answers0