“null” values shown in form fields in IE

。_饼干妹妹 提交于 2020-01-04 07:04:14

问题


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.


回答1:


Well, 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);


来源:https://stackoverflow.com/questions/5387038/null-values-shown-in-form-fields-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!