Problem with HiddenFor helper
Posted
by
Dmitry Borovsky
on Stack Overflow
See other posts from Stack Overflow
or by Dmitry Borovsky
Published on 2010-12-30T07:50:55Z
Indexed on
2010/12/30
7:53 UTC
Read the original article
Hit count: 268
c#
|asp.net-mvc
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?
© Stack Overflow or respective owner