<%: 和 <%= 与嵌入代码(表达式)块相同 [英] Are <%: and <%= the same thing as embbed code (expression) blocks
问题描述
刚开始使用 MVC 2 我注意到他们在他们的入门模板中使用
<%: Html.ActionLink("Home", "Index", "Home")%>
而且我确信在 MVC 1 中它是
<%= Html.ActionLink("Home", "Index", "Home")%>
它们是一样的吗?如果是这样,为什么从等号变为冒号.
冒号语法意味着您将被自动编码为 html:http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx
他们不能只对所有现有的 <%=
块进行 html 编码,因为已经正确编码的东西(希望大多数项目在那里)看起来很奇怪.>
Having just started with MVC 2 I notice that in their starter template they use
<%: Html.ActionLink("Home", "Index", "Home")%>
and I was sure that in MVC 1 it was
<%= Html.ActionLink("Home", "Index", "Home")%>
Are they the same thing? If so, why the change from equal sign to colon.
the colon syntax means you'll be html encoded automatically: http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx
They couldn't just html encode all the existing <%=
blocks, because things that are already properly encoded (which is hopefully most of the projects out there) would look strange.
这篇关于<%: 和 <%= 与嵌入代码(表达式)块相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!