I can't find this info anywhere. Probably because Google is ignoring the keywords. Is there a difference between using <%:
and <%=
in your aspx page? They seem interchangeable.
我在任何地方都找不到这个信息。可能是因为谷歌忽略了关键字。在您的aspx页面中使用<%:和<%=有区别吗?他们似乎可以互换。
3 个解决方案
#1
18
<%: %>
is a new thing in ASP.NET MVC 2. It is the same as <%= Html.Encode("Text") %>
. It is recommended to always use <%: %>
unless you have some specific reason to not do so (for example, you are rendering data from some file or database that's already been encoded).
<%: %>是ASP中的一个新事物。净MVC 2。它与<%= Html.Encode(“文本”)%>相同。建议始终使用<%:%>,除非您有特定的理由不这样做(例如,您正在从某个已经被编码的文件或数据库中呈现数据)。
#2
6
The difference is :
不同之处在于:
<%= "my <text>" %>
will output my <text>
, which is incorrect HTML
<%= "my
<%: "my <text>" %>
will output my <text>
, which is better
<%: "my
更多细节在这里
#3
6
@ntcolonel is right on the money. Additionally, for cases where your data has already been encoded, provide it using anything implementing IHtmlString
. This prevents double-encoding, and allows you to always use <%: %>
.
@ntcolonel先生在金钱上是对的。此外,对于已经对数据进行编码的情况,可以使用任何实现IHtmlString的方法提供数据。这可以防止双编码,并允许您始终使用<%:%>。
I believe that ASP.NET 4 shops should gravitate toward enforcing <%: %> by policy.
我相信,ASP。NET 4商店应该倾向于按策略执行<%:%>。
Also, the new syntax is for ASP.NET 4 in general; not necessarily just MVC, which is great news for WebForms developers.
另外,新的语法是针对ASP的。净4一般;不只是MVC,这对WebForms的开发者来说是个好消息。
#1
18
<%: %>
is a new thing in ASP.NET MVC 2. It is the same as <%= Html.Encode("Text") %>
. It is recommended to always use <%: %>
unless you have some specific reason to not do so (for example, you are rendering data from some file or database that's already been encoded).
<%: %>是ASP中的一个新事物。净MVC 2。它与<%= Html.Encode(“文本”)%>相同。建议始终使用<%:%>,除非您有特定的理由不这样做(例如,您正在从某个已经被编码的文件或数据库中呈现数据)。
#2
6
The difference is :
不同之处在于:
<%= "my <text>" %>
will output my <text>
, which is incorrect HTML
<%= "my
<%: "my <text>" %>
will output my <text>
, which is better
<%: "my
更多细节在这里
#3
6
@ntcolonel is right on the money. Additionally, for cases where your data has already been encoded, provide it using anything implementing IHtmlString
. This prevents double-encoding, and allows you to always use <%: %>
.
@ntcolonel先生在金钱上是对的。此外,对于已经对数据进行编码的情况,可以使用任何实现IHtmlString的方法提供数据。这可以防止双编码,并允许您始终使用<%:%>。
I believe that ASP.NET 4 shops should gravitate toward enforcing <%: %> by policy.
我相信,ASP。NET 4商店应该倾向于按策略执行<%:%>。
Also, the new syntax is for ASP.NET 4 in general; not necessarily just MVC, which is great news for WebForms developers.
另外,新的语法是针对ASP的。净4一般;不只是MVC,这对WebForms的开发者来说是个好消息。