Reputation: 299
I created an array like so
obj={}
obj['id'] = jQuery(this).attr("id");
obj['slotNum'] = tNumber;
I need to add this to an array and send it to controller via ajax and access this array in controller in MVC. Can you please advice? I tries creating
var arr=[];
arr.push(obj)
When I put it in alert, I can't see any values. Am I putting it write and how to pass the above array to MVC controller and read it.
Upvotes: 1
Views: 915
Reputation: 24648
obj
is an object, not an array.
You can use JSON.stringify()
to convert your array of objects into a string which can be sent in an ajax request:
var strArr = JSON.stringify( arr );
Then assign strArr
a parameter name in your ajax request:
$.ajax({
url: ....,
.......
data: {
mydata: strArr,
....
},
....
});
Upvotes: 1