Tuesday, 17 September 2013

Wrong default form values from model

Wrong default form values from model

I have a backup variable for an account's username that I save through
posts in a hidden field, @Html.HiddenFor(u => u.backupUsername). This is
the function the form posts to:
[HttpPost]
public ActionResult Update(AccountModel newInfo)
{
validateUserInfo(newInfo);
if (ModelState.IsValid)
{
newInfo.updateToDatabase();
}
return View(newInfo);
}
In updateToDatabase(), the backup username is updated to match the current
one. I've set breakpoints and looked at the values during debug to confirm
that this does happen and work.
However, as soon as Update() is called again, newInfo.backupUsername is
back to what it was before anything had been changed. What am I missing
here? Shouldn't the form's--and therefore the hidden field's--values get
repopulated from the model passed in?

No comments:

Post a Comment