Ajax.BeginForm - possible bug - MVC
If you have Html.Hidden(...)
inside Ajax.BeginForm
and you submit the form more than once and you're updating the v开发者_运维百科alue of the hidden field using ViewData
or whatever, it won't update. Maybe because Html.Hidden
is a server-side control. (Html.Hidden
is inside the UpdateTargetId div)
Another way things would break is if there is an Html.TextBox
inside Ajax.BeginForm
or something and you need to hide/show it based on what comes out of that Ajax Request using some kind of if, else clause. It won't appear/disappear.
This has been asked million times here and I've answered it million times - this is by design: HTML helpers always use the POSTed value when binding before looking at the ViewData or model. This basically means that you cannot change the value in the controller action and this is by design. You could write your own html helper if you don't like this design or simply:
<input type="hidden" name="foo" value="<%: ViewData["foo"] %>" />
If you use html helper:
<%: Html.Hidden("foo") %>
if there's a POSTed value foo
it is this value that is going to be used no matter what you put in ViewData
.
精彩评论