jquery - Changing value of a hidden field on postback -
i have spent day trying debug , need help. developing jquery mobile application in asp.net mvc 4. have form hidden field on it, value derived model property:
@<input type="hidden" id="hdnshowmsg" name="hdnshowmsg" value="@model.showmsg" />
after form submission, model.showmsg modified controller , form redisplayed. problem time view gets javascript (dom loaded), model.showmsg not show modified value still shows initial value (before post).
i found possible solution, describes situation exactly, clearing modelstate in controller not solve issue: http://blogs.msdn.com/b/simonince/archive/2010/05/05/asp-net-mvc-s-html-helpers-render-the-wrong-value.aspx
i understand how modelstate retains form field values can redisplay them in case of validation error. understand html helpers in view use modelstate first before using model. why still have issue if clear modelstate?
i put breakpoint in controller , verified modelstate cleared, when view redisplayed after postback, following javascript code displays old value:
<script> $(document).ready(function () { alert(document.getelementbyid("hdnshowmsg").value); }); </script>
how can be?
here html helper form:
@using html.beginform("index", "newdocument", model, formmethod.post, new {.id = "newdocument-form"})
Comments
Post a Comment