What is difference between these tags <% <%: <%= in ASP.NET MVC 2?
The tit开发者_运维技巧le contain my whole question.
<% /* 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" %>
For a good explanation about the <%, <%= and <%# syntax and their usage, please read this article.
The <%: syntax is new in .Net 4 and is used for encoding HTML output. See this article of ScottGu for more information about that.
<% %>
is used just to execute server side code
ex. <% if(oject){...} %>
<%= %>
is used execute server side code and return value
ex. <%=Html.Encode(Item["Name"]) %>
<%: %>
is used execute server side code but it will return Html
Encoded string
ex. <%Item["Name"] %>
Source : What is difference between these tags <%, <%: , and <%= in ASP.NET MVC 2?
精彩评论