开发者

In ASP.NET MVC what are the differences between "<%=", "<%:" "<%#"

开发者 https://www.devze.com 2023-03-19 06:18 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消