相关疑难解决方法(0)

通过JSON将对象数组发布到ASP.Net MVC3

我正在寻找通过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)

arrays post json asp.net-mvc-3

65
推荐指数
3
解决办法
7万
查看次数

标签 统计

arrays ×1

asp.net-mvc-3 ×1

json ×1

post ×1