剃刀代码编辑器默认显示``?'' [英] Razor code EditorFor showing '�' as default?
本文介绍了剃刀代码编辑器默认显示``?''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的表单中,有一个文本框,使用EditorFor的剃须刀代码提供,为此提供的类型为 Char .但是它总是默认显示一个``...'',这是什么意思?是因为 char 类型?
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?
请看图片
推荐答案
这是无效的Unicode代码点字形.在大多数浏览器中,当它们遇到空字符'\ 0'(U + 0000)时,就会看到它.这恰好是.NET char
数据类型的默认值.
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.
三种解决方法:
- 将有效的char替换为默认的char,例如空格:
c == default(char)?'':c
- 添加逻辑以在值为
default(char)
时隐藏 - 将数据类型更改为
System.String
,这将导致在null
和String.Empty
两种情况下均能正确表示格式
EditorFor
或 LabelFor
- 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
这篇关于剃刀代码编辑器默认显示``?''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文