为什么@ Html.Label()去除一些字符 [英] Why is @Html.Label() removing some characters
问题描述
当我用下面的code在我的Razor视图它呈现<标签=> someText< /标签>
,而不是<标签=大于1。 someText< /标签>
,但我不明白,为什么 1
在渲染时被删除
@ Html.Label(的String.Format({0}。SomeText则会,1))
编辑:
下面code呈现<标签=> 1#someText< /标签>
如预期
@ Html.Label(的String.Format({0}#SomeText则会,1))
正在滥用的 Html.Label 方法。它是:
返回一个HTML标签元素和属性的属性名
这是由指定的前pression psented重新$ P $。
块引用>这就是为什么它会很困惑,如果你有一个点
。
在第一个参数,因为它需要一个属性ex pression那里。不过,您可以使用第二个重载:
@ Html.Label(,的String.Format({0}。SomeText则会,1))
或者只是写出来的HTML:
<标签> @的String.Format({0} someText,1) - ; /标签>
When I use the following code in my razor view it renders
<label for=""> someText</label>
and not<label for="">1. someText</label>
but I can't figure out why1.
is removed while rendering.@Html.Label(String.Format("{0}. someText",1))
Edit: The following code renders
<label for="">1# someText</label>
as expected.@Html.Label(String.Format("{0}# someText",1))
解决方案You are misusing the Html.Label method. It is for:
Returns an HTML label element and the property name of the property that is represented by the specified expression.
That's why it gets confused if you have a point
.
in the first parameter because it expects a property expression there.However, you can use the second overload:
@Html.Label("", String.Format("{0}. someText",1))
Or just write out the HTML:
<label>@String.Format("{0}. someText", 1)</label>
这篇关于为什么@ Html.Label()去除一些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!