标题包含我的整个问题。这些标记与ASP.NET MVC 2中的<%<%:<%=有什么区别?
-1
A
回答
7
<% /* Is a codeblock */ for(int i = 0;i<5;i++) { } %>
<%= "Writes something to the output stream" /* Response.Write */ %>
<%: "HTML-encodes this <b>hello</b> to the output stream" %>
2
有关<%,<%=和<%#语法及其用法的详细说明,请参阅this article。
<%:语法是.Net 4中的新增功能,用于编码HTML输出。有关详细信息,请参阅this article of ScottGu。
0
<% %>
只是用来执行服务器端代码
前。 <% if(oject){...} %>
<%= %>
用于执行服务器端代码和返回值
离。 <%=Html.Encode(Item["Name"]) %>
<%: %>
用于执行服务器端代码,但它会返回的Html 编码字符串
前。 <%Item["Name"] %>
来源:What is difference between these tags <%, <%: , and <%= in ASP.NET MVC 2?