Razor code EditorFor showing '�' as default?

左心房为你撑大大i 提交于 2020-05-16 08:06:26

问题


In my Form, there is a textbox, in razor code using EditorFor and the type given for this is Char. But it always shows a '�' as default, what's that mean? is this because of char type?

please look at the picture


回答1:


This � is the invalid unicode code point glyph. It is what you will see in most browsers when they encounter the null character '\0' (U+0000). This happens to be the default value of the .NET char data type.

Three workarounds:

  1. substitute a valid char for the default, for example a space: c == default(char) ? ' ' : c
  2. add logic to hide the EditorFor or LabelFor when the value is default(char)
  3. change the data type to System.String, which leads to correct rendition in both cases null and String.Empty


来源:https://stackoverflow.com/questions/61339819/razor-code-editorfor-showing-as-default

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