[英]Backbone save, model data not recieved on the server
我在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
}
});
{"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;
}
我真的不能指出這里有什么魚。 但是我還是骨干新手,所以我很容易錯過一些東西。 誰能看到什么問題?
主要問題是模型上有公共字段,而不是屬性。 簡單的問題,不是那么容易找到。 這篇文章對我有幫助- 如何使用json將復雜類型傳遞給ASP.NET MVC控制器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.