我有如下定义的域模型:
public class myModel {
public string Prop1 {get;set;}
public string Prop2 {get;set;}
public List<myClass> ListofStuff {get;set;}
}
public myClass {
public string Id{get;set;}
public string Name{get;set;}
}
接下来我定义了控制器动作如下:
[HttpPost]
public ActionResult Save(MyModel someModel )
{
//do the saving
}
我使用 jQuery Ajax 在我的 JS 代码中调用上述操作
var someModel = { Prop1: "somevalue1",
Prop2: "someothervalue",
ListofStuff: [{Id: "11", Name:"Johnny"}, {Id:"22", Name:"Jamie"}]
};
$.ajax({
contentType: 'application/json, charset=utf-8',
type: "POST",
url: "/myController/Save",
data: JSON.stringify({someModel: someModel}),
cache: false,
dataType: "json",
success: function () {
alert('success!');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('error');
}
});
编辑后: 当我运行上面的代码时,遇到了错误处理程序。我尝试安装Firebug,但我的FF版本为8,无法安装它。所以我不确定是什么错误或如何查看它。
我做错了什么?