I'll make it simple, here's the code I've got.
public ActionResult DeleteNonCIStaffUser(int id)
{
return View(_contractsControlRepository.FetchNonCIStaffUserByID(id));
}
[HttpPost]
public ActionResult DeleteNonCIStaffUser(ContractUser contractUser)
{
try
{
_contractsControlRepository.DeleteNonCIStaffUser(contractUser.User_Key);
return RedirectToAction("NonCIStaffUsers"); // never reaches this as an exception is thrown!
}
catch
{
ViewData["ExceptionMessage"] = "Exception caught!";
return View(contractUser); // I'm expecting this statement to return the ContractUser object instantiated with the same data as the GET action.
}
}
The HttpPost
contains the ContractUser
object. Upon the postback I am left with nothing, the contractUser object no longer exists, which I find rather odd. FetchNonCIStaffByUser(int)
brings back a ContractUser object (which works). The delete page shows information from this object, so I know the initial entry works, it's just the postback if there's an error, no information is displayed from the ContractUser
object.
Any ideas why this is happening? I'd have expected the contractUser
object to be returned to the view.
FIXED
<%= Html.Hidden("FullName", Model.FullName) %>
<%= Html.Hidden("User_Key", Model.User_Key) %>
Neither fields were actually being put in form elements in the page so nothing was being posted back. Good to know.