我正在使用带有 ASP.NET MVC 的骨干网。我想将模型保存到服务器。
文件夹型号
Folder = Backbone.RelationalModel.extend({
url: "/SaveFolder",
relations: [
{
type: Backbone.HasMany,
key: 'Files', /*key should match the JSON name*/
relatedModel: 'FileModel',
collectionType: 'FileCollection',
}
],
idAttribute: "FolderID"
});
视图中的文件夹保存代码
var newFolder = new Folder();
newFolder.set("FolderName", newFolderName);
newFolder.set("EditableByOthers", "N");
newFolder.save({
success: function(model, response, options) {
alert("success"); //not reached
},
error: function (model, xhr, options) {
alert("error"); //not reached
}
});
注意:成功和错误警报永远不会触发。
当我签入 Fiddler 时,发送的 JSON 是 -
{"Files":[],"FolderName":"new","EditableByOthers":"Y"}
但是,我在服务器端的控制器收到一个空的文件夹对象-
[HttpPost]
public ActionResult SaveFolder(Folder newFolder) //All properties of newFolder are null, or "N" in case of boolean
{
string name = newFolder.FolderName;
return null;
}
服务器上的文件夹类 -
public class Folder
{
public int? FolderId { get; set; }
public int UserId;
public string FolderName;
public bool EditableByOthers;
public IList<File> Files;
}
我真的不能指出这里有什么可疑之处。但同样,我是一个骨干新手,所以我很容易错过一些东西。任何人都可以看到有什么问题吗?