How to pass the list of objects from view to MVC controller using json.stringify

前端 未结 2 1135
谎友^
谎友^ 2021-01-22 00:16

I have tried with following code but shows null in the controller side..

view:



        
2条回答
  •  旧时难觅i
    2021-01-22 00:53

    There is problem with data that you are sending to server. you don't need to JSON.stringify 2 times.

     function getme() {
        debugger;
        var emp = [
        { empid: 1, name: 'sasi' },
        { empid: 2, name: 'sathish' }
        ];
        emp = JSON.stringify({ emp: emp });//make json string once 
        $.ajax({
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            type: 'POST',
            url: '/Home/getemplist',
            data: emp //send it to server
        });
     }
    

提交回复
热议问题