CSS显示模板类名中的额外空间

Hen*_*o12 6 css c# display-templates asp.net-mvc-4 jquery-datatables

我在我的C#MVC4应用程序中使用显示模板来构建我希望我的自定义模型在我的视图中的数据表中显示的方式.对于数据表,我使用datatables.net.在下面的代码中,我给每个<td>类名"对齐",但是当我运行应用程序并检查元素时,分配的类名在末尾有一个空格,例如"aligned"

@using System;
@model MyProject.Models.CellValueViewModel

<td class="aligned">
    @{if(Model.Value.StartsWith("<input type='checkbox'"))
      {
          @Html.Raw(Model.Value);
      }     
      else if(Model.Value == String.Empty)
      {
          @Html.Encode(0.00);
      }     
      else
      {
          @Html.DisplayFor(x => x.Value);
      }
    }
</td>
Run Code Online (Sandbox Code Playgroud)

任何人都可以提供为什么会这样吗?

Sco*_*rry 1

根据您保存文档的方式,有时 Windows 会添加额外的字符。有时我会在使用带有签名的 UTF-8 编码保存的文档中看到类似这样的奇怪行为。

1) 要查看这是否是您遇到问题的原因,请转到文件->另存为;

2)在“保存”按钮上单击向下箭头并选择“使用编码保存”

3)确保选择不带编码的utf8。已经接近底部了。4)确保您没有选择靠近选项顶部的utf8编码。