簡體   English   中英

主干保存,服務器上未收到模型數據

[英]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
        }
    });

注意:成功和錯誤警報永遠不會觸發。

當我檢入Fiddler時,發送的JSON是-

{"Files":[],"FolderName":"new","EditableByOthers":"Y"}

但是,服務器端的控制器接收到一個空的Folder對象-

    [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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM