gpt4 book ai didi

asp.net-mvc-3 - 为什么 @Html.Label() 删除一些字符

转载 作者:行者123 更新时间:2023-12-03 05:07:36 24 4
gpt4 key购买 nike

当我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com