I am having problems posting a JSON array of objects to an ActionResult in Asp.Net MVC where the list of objects received is always null.
Here is the offending code:
Javascript:
var lineItems = new Object();
lineItems.Entrys = new Array()
var i = 0;
var currentId = 0;
$('#pages-table td.PageId').each(function () {
currentId = $(this).html().toString().trim();
lineItems.Entrys[i] = new Object({ ID: currentId, POS: i });
i++;
});
$.ajax({
url: 'UpdatePageOrder',
data: JSON.stringify(lineItems),
contentType: 'application/json',
dataType: 'json',
traditional: true,
type: 'POST',
success: function (result) {
}
});
Asp.Net MVC
public class PageOrder
{
public string ID { get; set; }
public string POS { get; set; }
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdatePageOrder(List<PageOrder> list)
{
var newPageOrderList = list;
... list is always null
}
Fiddler TextView:
{"Entrys":[{"ID":"0","POS":"7"},{"ID":"1","POS":"3"}]}
EDIT *
Downloaded MVC2 Futures and added to OnApplicationStarted (I'm using ninject)
ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());