I am working in MVC2 and .net framework 3.5
While trying to pass a single object to mvc controller it is working fine. But when I try to pass the value as an array, I'm getting property values as null in the controller.
I'm using the below code to do this.
JavaScript
var tdmsConfiguredLayersList = [{Id:1,Name:'Test1'},{Id:2,Name:'Test2'}];
$.ajax({
type: "POST",
//contentType: 'application/json; charset=utf-8',
//JSON.stringify({ layers: tdmsConfiguredLayersList }),
data:{layers:tdmsConfiguredLayersList},
url: rootUrl + "Map/CatalogueDrawing",
dataType: "json",
success: function (result) {
debugger;
},
error: function (errResult) {
debugger;
}
});
Controller Code
[HttpPost]
public void CatalogueDrawing(List<LayerViewModel> layers)
{
}
LayerViewModel class
public class LayerViewModel
{
public int Id { get; set; }
public string Name { get; set; }
}

contentType: 'application/json; charset=utf-8',and usedata: JSON.stringify({ layers: tdmsConfiguredLayersList })MapController, then useurl:'@Url.Action("CatalogueDrawing", "Map")',- don't hard code url's)JsonValueProviderFactoryand also this article. Otherwise you may need to generate the data to use the defaultapplication/x-www-form-urlencoded; charset=UTF-8- i.e.data: { [0].Id: 1, [0].Name: 'Test1', [1].Id: 2, [1].Name: 'Test2' },