我有一个循环
<ul id="news-list" class="thumbobs-list">
@foreach (var item in Model.News) {
@Html.Partial("RenderNews/" + item.TypeString, item)
}
</ul>
像这样使用偏音
@model Web.Models.DataModel.NewsItem
@{ Layout = null; }
<li class="news-item @Model.TypeString.ToLower()" id="id-@Model.Id">
<h3 class="headline">
Example News headline.
</h3>
<p class="timestamp">@Model.TimeString</p>
</li>
效果很好
但是当我使用 css 设置样式时,我遇到了一个导致问题的隐藏空白字符
在每个部分前面有一个空格、一个 U+FEFF 和另一个导致设计问题的空格。
有人见过吗?
最佳答案
您已经发现了 BOM,即字节顺序标记。它存储为文本文件中的第一个字节以指示编码。
http://en.wikipedia.org/wiki/Byte_order_mark
[编辑]
您可以使用记事本打开文件并“另存为...”为 ANSI。这将删除 BOM(和编码)。
// reading a text file as binary will include the BOM flag
FileStream FS = new FileStream(MapPath(@"~\Text\TestUTF8.txt"), FileMode.Open);
byte[] Data = new byte[100];
FS.Read(Data, 0, 100); // BOM is in the data
FS.Close();
// get rid of the BOM
String String1 = System.Text.Encoding.UTF8.GetString(Data);
// reading a text file as text will automatically handle it.
String String2 = File.ReadAllText(MapPath(@"~\Text\TestUTF8.txt"));
关于asp.net-mvc-3 - MVC3 Razor 循环中奇怪的隐藏字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8423159/