What you are doing wrong is that you are trying to modify the value of a POSTed variable in your controller action. So I suppose you are trying to do this:
[HttpPost]
public ActionResult Foo(SomeModel model)
{
model.CurrentStep = Steps.SomeNewValue;
return View(model);
}
and html helpers such as HiddenFor will always first use the POSTed value and after that the value in the model.
So you have a couple of possibilities:
-
Remove the value from the modelstate:
[HttpPost] public ActionResult Foo(SomeModel model) { ModelState.Remove("CurrentStep"); model.CurrentStep = Steps.SomeNewValue; return View(model); }
-
Manually generate the hidden field
<input type="hidden" name="NextStep" value="<%= Model.CurrentStep %>" />
-
Write a custom helper which will use the value of your model and not the one that’s being POSTed