0

firstly sorry for my bad english, my problem is, i have a controller that receive a list of object as param, but when i try sent this list to controller always receive null.

    public async Task<ActionResult> MyAction(List<class> object)
    {

        //do stuff
    }

my javascript

var array= []

array.push()...
document.location = '/MyAction/Controller?object'JSON.stringify(array)

my controller always receive null

i alreay tried use ajax, but for some reason ajax call my controler twice, in first call i recieve my list correctly, but in second receive null

       
       var array =[]
       array.push()//just example
       
       $.ajax({
            type: 'POST',
            tradicional:true,
            async:true,
            url: '/controller/MyAction',
            data: JSON.stringify({ 'object': array}),
            contentType: 'application/json; charset=utf-8',
            datatype: 'json',
            success: function (result) {
                //if succes then load my View passing array as param
                document.location = '/controller/MyAction?object' + JSON.stringify(array) ;

            },
            error: function (result) {

            }
        });

1 Answer 1

0

i alreay tried use ajax, but for some reason ajax call my controler twice

I'm guessing the first call is a POST request done by the lines:

$.ajax({
    type: 'POST',

and the second call is a GET request done by the line:

  //if succes then load my View passing array as param
  document.location = '/controller/MyAction?object' + JSON.stringify(array) ;

Check if this is the case in the "network" tab of your browser's debugger, decide whether you want to use POST or GET, and configure your controller accordingly. This thread may be helpful: asp mvc http get action with object as parameter

Sign up to request clarification or add additional context in comments.

2 Comments

if i not add this: //if succes then load my View passing array as param document.location = '/controller/MyAction?object' + JSON.stringify(array) ; After sent to controller the view not load
If does load, it's in the "response" param of the "success" function. It does not display, though. Can you do "console.log(response)" in the success handler?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.