下面的代码是一个很好的例子:
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);
}
1条答案
按热度按时间b4lqfgs41#
将
url: '/users/Edit/' + myUser.get('id'),
替换为url: '/users/Edit/',