我正在寻找通过JSON将对象数组发布到MVC3的解决方案.
我正在处理的示例代码:http: //weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx
JS:
var data = { ItemList: [ {Str: 'hi', Enabled: true} ], X: 1, Y: 2 };
$.ajax({
url: '/list/save',
data: JSON.stringify(data),
success: success,
error: error,
type: 'POST',
contentType: 'application/json, charset=utf-8',
dataType: 'json'
});
Run Code Online (Sandbox Code Playgroud)
ListViewModel.cs:
public class ListViewModel
{
public List<ItemViewModel> ItemList { get; set; }
public float X { get; set; }
public float Y { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
ItemViewModel.cs:
public class ItemViewModel
{
public string Str; // originally posted with: { get; …
Run Code Online (Sandbox Code Playgroud)