【问题标题】:Backbone does not send model values to the server apiBackbone 不会将模型值发送到服务器 api
【发布时间】:2016-10-16 15:41:00
【问题描述】:

我有以下代码作为更新用户的 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);
}

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多