“null” values shown in form fields in IE

2019-07-17 08:40发布

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).

enter image description here

Any clue how to fix this? Thanks.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-07-17 09:22

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);
查看更多
登录 后发表回答