我有以下代码作为更新用户的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);
}
答案 0 :(得分:0)
将url: '/users/Edit/' + myUser.get('id'),
替换为url: '/users/Edit/',