admin管理员组文章数量:1291109
I use Html helpers to display model data in form fields, e.g. Html.TextBoxFor, Html.TextAreaFor.
When the model values are null, I would expect the values should be empty in the form fields. They are displayed normally in Safari and Firefox, i.e. empty, but in IE, they are shown as "null" in a text field (see image below).
Any clue how to fix this? Thanks.
I use Html helpers to display model data in form fields, e.g. Html.TextBoxFor, Html.TextAreaFor.
When the model values are null, I would expect the values should be empty in the form fields. They are displayed normally in Safari and Firefox, i.e. empty, but in IE, they are shown as "null" in a text field (see image below).
Any clue how to fix this? Thanks.
Share Improve this question edited Mar 24, 2011 at 1:29 William Niu asked Mar 22, 2011 at 5:02 William NiuWilliam Niu 15.9k8 gold badges57 silver badges93 bronze badges 2- What version of IE are you using? – byte Commented Mar 23, 2011 at 9:46
- I just found out that, it's not ASP.NET MVC's problem; it's JavaScript... :p I am still investigating the cause though. – William Niu Commented Mar 24, 2011 at 0:01
1 Answer
Reset to default 8Well, it turned out to be JavaScript's problem (with IE, that is). In the following statement, if value == null
, IE would display null
in the textbox (or textarea).
$('#someTextBox').val(value);
The quick fix is simply display an empty string instead...
$('#someTextBox').val(value == null ? '' : value);
本文标签: javascriptquotnullquot values shown in form fields in IEStack Overflow
版权声明:本文标题:javascript - "null" values shown in form fields in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741518619a2383045.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论