I am making an ajax call form the javascript to MVC controller, passing the array of object to controller action.
Js Code :
function Constructor(p1, p2) {
this.foo = p1;
this.bar = p2;
}
var Obejct_Array = new Array();
Obejct_Array[Obejct_Array.length] = new Constructor("A", "B");
Obejct_Array[Obejct_Array.length] = new Constructor("C", "D");
$.post("/_Controller/_Action", { ObjectArray : Obejct_Array });
C# code
public Class Example
{
public string foo { get; set; }
public string bar { get; set; }
public string Prop3 { get; set; }
}
//Action in Controller
public void _Action(Example[] ObejctArray)
{
//Here the size of ObjectArray is 2 but the properties are all null. Whats the problem ?
}
Both entries from javascript array is passing to the controller`s action method but the property values are showing null. Can anybody tell me the problem ?
JSON.stringify(Obejct_Array), and I'm guesing you'd want that as a string since it's an array and all, and just convert it back on the server.