Because the "original" is stored in ModelState. When form values are collected on the MVC side, they are stored in the ModelState . You used the used Html.TextBox helper. When you recreate the view after POST, it first looks at ModelState, and if there is a value, it sets that value. The value in the model object is no longer taken into account.
One solution is to follow the POST-REDIRECT-GET pattern. First POST, do something with the data, and then redirect:
[HttpPost] public ActionResult Index(MyModel appModel) {
If you want to pass something between redirects, you can use TempData :
[HttpPost] public ActionResult Index(MyModel appModel) { //do something with data TempData["Something"] = "Hello"; return RedirectToAction("Index"); } [HttpGet] public ActionResult Index() { var something = TempData["Something"]; //after redirection it contains "Hello" }
After the redirect, ModelState does not work, so the value is not overridden. The POST-REDIRECT-GET template also helps to get rid of the effect of reponing the form when you press F5 in the browser.
source share