问题
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:
- substitute a valid char for the default, for example a space:
c == default(char) ? ' ' : c
- add logic to hide the
EditorFor
orLabelFor
when the value isdefault(char)
- change the data type to
System.String
, which leads to correct rendition in both casesnull
andString.Empty
来源:https://stackoverflow.com/questions/61339819/razor-code-editorfor-showing-as-default