I have a form in my MVC application that has a textbox. When the form is POSTed to the page, I make a modification to the model value and redisplay the view. The textbox still shows the value that was POSTed though.
Here is the code:
@using( Html.BeginForm() ) {
@Html.TextBoxFor( m => m.Foo )
<input type="submit" value="Save" />
}
public class TestController : Controller {
public ActionResult Index() {
return View();
}
[HttpPost]
public ActionResult Index(MyModel model) {
model.Foo += "bar";
return View(model);
}
}
Whatever is in the form (lets say I type in foo) I add "bar" and try to show the form again. But when the form is redisplayed all I see is foo. I remember reading something about why this is happening but can't seem to find it now. I know this is a poor example but I'm just trying to remember why it is doing this, and what the workaround is (other than redirecting). Is there a way to have it show the updated model value and not what the form value that was posted?