asp.net mvc postback
Posted
by
user266909
on Stack Overflow
See other posts from Stack Overflow
or by user266909
Published on 2010-01-26T03:39:55Z
Indexed on
2012/10/04
3:38 UTC
Read the original article
Hit count: 109
I have a controller with the following two Edit methods. The edit form displays correctly with all additional dropdown lists from the FormViewModel. However, when I changed some field values and submitted the form. None of the changed fields were saved. The fields in the postbask collection have default or null values. I have another edit form which update another table. On submit, the changed values are saved. Does anyone know why?
// GET: /Transfers/Edit/5
public ActionResult Edit(int id)
{
Transfer transfer = myRepository.GetTransfer(id);
if (transfer == null)
return View("NotFound");
return View(new TransferFormViewModel(transfer));
}
//
// POST: /Transfers/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, Transfer collection)
{
Transfer transfer = vetsRepository.GetTransfer(id);
if (transfer == null)
return View("NotFound");
else
{
try
{
UpdateModel(transfer);
vetsRepository.Save();
return RedirectToAction("Details", new { id = transfer.TransfersID });
}
catch
{
ModelState.AddModelErrors(transfer.GetRuleViolations());
return View(new TransferFormViewModel(transfer));
}
}
}
© Stack Overflow or respective owner