<%: 和 <%= 与嵌入代码(表达式)块相同 [英] Are <%: and <%= the same thing as embbed code (expression) blocks

查看:22
本文介绍了<%: 和 <%= 与嵌入代码(表达式)块相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用 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.

这篇关于&lt;%: 和 &lt;%= 与嵌入代码(表达式)块相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆