I'm wondering why do we have to force @Value on field to send back different data after a post:
public ActionResult Index()
{
var obj = new MyObject();
obj.aString = "initial value";
return View(obj);
}
[HttpPost]
public ActionResult Index(MyObject obj)
{
obj.aString = "something else";
return View(obj);
}
@using (Html.BeginForm())
{
@Html.HiddenFor(model => model.aString)
<input type="submit" />
}
If we do something like this, the hidden field is not "something else" after postback, but if I write this:
@Html.HiddenFor(model => model.aString, new { @Value = Model.aString})
Now aString will be "something else" after postback.
So why does it work like this ? It's not convenient at all.
Thank you!