This is happening because whenever you return an object from a POST
, in MVC, it is assuming that you are doing that because there was a validation error so instead of filling the form with the model values in your controller MVC is grabbing the values from the ModelState
.
The quick "solution" is to use ModelState.Clear()
but this is not recommend since you are basically ignoring MVC built-in functionality.
You could, as you already noticed, not use the Html Helpers or look into using the Post-Redirect-Get pattern.
Using ModelState.Clear()
, just in case you want to ignore the "do-not-use-this-workaround" warning:
public ActionResult Index(Testmodel model)
{
model.Test++;
ModelState.Clear();
return View(model);
}