Problem with HiddenFor helper
- by Dmitry Borovsky
Hello.
Model:
public sealed class Model
{
public string Value { get; set; }
}
Controller:
[HandleError]
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View(new Model { Value = "+" } );
}
[HttpPost]
public ActionResult Index(Model model)
{
model.Value += "1";
return View(model);
}
}
View:
<%using (Html.BeginForm()){%>
<%: Model.Value %>
<%: Html.HiddenFor(model => model.Value) %>
<input type="submit" value="ok"/>
<%}%>
Every time I submitted form result is
<form action="/" method="post">+1
<input id="Value" name="Value" type="hidden" value="+">
<input type="submit" value="ok">
</form>
It means that HiddenFor helper doesn't use real value of Model.Value but uses passed to controller one. Is it bug in MVC framework? Does anyone know workaround?