当我在 Razor View 中使用以下代码时,它会呈现 <label for=""> someText</label>
而不是<label for="">1. someText</label>
但我不明白为什么 1.
渲染时被删除。
@Html.Label(String.Format("{0}. someText",1))
编辑:
以下代码呈现 <label for="">1# someText</label>
正如预期的那样。
@Html.Label(String.Format("{0}# someText",1))
最佳答案
您滥用了 Html.Label方法。它的用途是:
Returns an HTML label element and the property name of the property that is represented by the specified expression.
这就是为什么如果第一个参数中有一个点.
,它会感到困惑,因为它需要一个属性表达式。
但是,您可以使用第二个重载:
@Html.Label("", String.Format("{0}. someText",1))
或者直接写出 HTML:
<label>@String.Format("{0}. someText", 1)</label>
关于asp.net-mvc-3 - 为什么 @Html.Label() 删除一些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10227775/