I have a page which is strongly typed to my "User" class. When it is loaded, I load it by Id from the database and pass it to the view.
When the edit form is posted, the object gets posted to the controller method fine, with some other parameters. The object has its properties filled from the form, but it's ID (which obviously isnt on the form) doesnt get posted.
Even when I manually set it to an ID in code and try and save my context, nothing happens on the database.
Here is a rough view of the code with stuff taken out for brevity.
public ActionResult MyProfile()
{
ViewData["Countries"] = new SelectList(userService.GetCountries(), "id", "name");
return View(userService.GetById(CurrentUser.id));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyProfile(MSD_AIDS_Images_Data.LINQRepositories.User user, string password2)
{
user.id = CurrentUser.id; //user id isn't posted, so need to reassign it
userService.SaveChanges();
}
I have written code like this a dozen times and it has worked, what is going wrong?
EDIT
When I debug the user object, it's PropertyChanged and PropertyChanging properties are set to NULL