標題包含我的整個問題。這些標記與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?