This is the weirdest behaviour I have encountered in default set of controls/helpers in ASP.NET MVC
I post a textarea value as such:
<%:Html.TextAreaFor(x=>x.Data.Body,new {style="display:none;", @class="ckeditor"}) %>
In my controller action I return a different value for Data.Body (i.e. model.Data.Body = "junk"), yet I still see the originally posted value inside the textarea box.
If I do
<textarea id="Data.Body" name="Data.Body" style="开发者_JAVA百科display:none;" class="ckeditor">
<%=Model.Data.Body %>
</textarea>
It works as expected.
Any insight?
Thanks.
This is by design - the HTML Helpers will redisplay the posted data and not what is in the model. They assume you will use the Post-Redirect-Get pattern and that on a successful post you should redirect to a GET method. If you are redisplaying info after a post, the helpers assume there has been an error and they display the original posted values so the user can 'correct' them.
You can ModelState.Clear if you don't want this to occur, but I would consider programming around the standard PRG pattern of post-redirect-get.
I ran into this a while back - see my posting here: Updating value provider prior to TryUpdateModel
精彩评论