c# - Backbone 不会将模型值发送到服务器 api

标签 c# mysql asp.net-mvc backbone.js

我有以下代码作为更新用户的javascript:

updateUser: function (userResponse) {
    var userNameEdit = this.$el.find("#txtNameEdit").val();
    if (userNameEdit != "") {
        var myUser = new user();
        myUser = this.collection.models[0];
        //myUser.set({ username: 'testaaaa' });
        myUser.save({ username: userNameEdit, email: 'aaaa@aaa' }, {
            url: '/users/Edit/' + myUser.get('id'),
            wait: true,
            success: function () {
                var templateTemp = $("#personTemplate").html();
                this.$el.html(_.template(templateTemp, { name: myUser.get('name') }));
            },
            error: function () { alert('update error'); }
        });
    }
},

当我在服务器端检查用户对象时,它具有默认值!

[HttpPut]
//[ValidateAntiForgeryToken]
public ActionResult Edit(user user)
{
    if (ModelState.IsValid)
    {
        _context.Entry(user).State = EntityState.Modified;
        _context.SaveChanges();
        return RedirectToAction("Index");
    }
    return View(user);
}

最佳答案

url: '/users/Edit/' + myUser.get('id'), 替换为 url: '/users/Edit/',

关于c# - Backbone 不会将模型值发送到服务器 api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37836873/

相关文章:

c# - MVC MapPageRoute 和 ActionLink

asp.net-mvc - 为什么 Html.ActionLink 呈现 "?Length=4"

c# - HttpClient 已断开连接。试图读取流的末尾

mysql - 嵌套游标中的变量用法

mysql - 将 CSV 导入 MySQL 时遇到困难

javascript - Mysql Escape()时防止单引号

c# - $ajax 完成功能在 ASP.NET -MVC5 应用程序中不起作用

c# - 在 C# 中编写匿名函数的推荐方法是什么?

c# - Unity - 根据某些条件解决依赖关系

c# - 将 LinqDataSource 绑定(bind)到两个单独的表