简体   繁体   English

Razor 代码编辑器默认显示“�”?

[英]Razor code EditorFor showing '�' as default?

In my Form, there is a textbox, in razor code using EditorFor and the type given for this is Char .在我的表单中,有一个文本框,在 razor 代码中使用 EditorFor ,为此给出的类型是Char But it always shows a '�' as default, what's that mean?但它总是默认显示一个“...”,这是什么意思? is this because of char type?这是因为char类型吗?

please look at the picture请看图片在此处输入图像描述

This � is the invalid unicode code point glyph.这是无效的 unicode 代码点字形。 It is what you will see in most browsers when they encounter the null character '\0' (U+0000).这是您在大多数浏览器中遇到 null 字符 '\0' (U+0000) 时会看到的内容。 This happens to be the default value of the .NET char data type.这恰好是 .NET char数据类型的默认值。

Three workarounds:三种解决方法:

  1. substitute a valid char for the default, for example a space: c == default(char)? ' ': c将有效字符替换为默认值,例如空格: c == default(char)? ' ': c c == default(char)? ' ': c
  2. add logic to hide the EditorFor or LabelFor when the value is default(char)添加逻辑以在值为default(char)时隐藏EditorForLabelFor
  3. change the data type to System.String , which leads to correct rendition in both cases null and String.Empty将数据类型更改为System.String ,这在nullString.Empty两种情况下都会导致正确的再现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM