Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between <% %> and <%=%>?

What is the difference between <% %> and <%= %> in ASP.NET MVC? And when to use which?

like image 629
Graviton Avatar asked Oct 13 '08 08:10

Graviton


1 Answers

See also this question. MVC hasn't changed how these bee-stings work, just how often they're used.

Basically:

  • <% - execute code
  • <%@ - page directive
  • <%$ - resource access
  • <%= - explicit output to page
  • <%# - data binding
  • <%-- - server side comment block

Also new in ASP.Net 4:

  • <%: - writes out to the page, but with HTML encoded
like image 68
Keith Avatar answered Sep 19 '22 11:09

Keith