看法
@using (Html.BeginForm("UpdateClient", "Client")) {
控制器
[HttpPost]
public ActionResult UpdateClient(Client client)
{
if (ModelState.IsValid) {
bool ret = _clientRepository.UpdateClient(client);
return RedirectToAction("Index", "Home");
}
return View(client);
}
存储库
public bool UpdateClient(Client client)
{
using (var context = new Entities()) {
context.AttachTo("Clients",client);
context.ObjectStateManager.ChangeObjectState(client, EntityState.Modified);
context.SaveChanges();
}
return true;
}
当我在控制器中调用 UpdateClient 时,客户端 ID 为 0。如何传递我已更新的 ID?