In ASP.NET MVC what are the differences between "<%=", "<%:" "<%#"
I've tried to perform a search on the above query but probably due to the angle brackets, I didn't find anything on the matter.
Could anyone please explain what the differences are between <%=
, <%:
<%#
?
I seem to recall that <%#
is preferred over <%=
but I am 开发者_JAVA百科not sure why.
The following article describes them pretty well.
<%=
: Rendering Code Syntax<%: %>
: HTML encoded renedring (same usage as<%=
)<%# %>
: Data Binding Syntax - works with server side controls in classic WebForms applications, inapplicable in MVC
<%= xxx %>
Inserts the text in xxx into the page at that location. (more info)
<%: xxx %>
Same as above except it html encodes the text for your convenience - (Except if xxx is an HtmlString which indicates it is already encoded)
<%# xxx %>
Same as the first one too except xxx is only evaluated when DataBind() is called on the form (not really applicable in MVC) (more info)
Martin
精彩评论